Java: URL or string?

Are there any advantages (coding style, OOP best practice, etc.) when working with an instance java.net.URL, unlike java.lang.Stringwhen I can be sure that the URL is valid in any case (maybe I set it statically in the file properties), and I will just work with it in my string form (for example, print it in a JSP file)?

+5
source share
3 answers

java.net.URL. You must use java.net.URI. You should transfer objects whenever possible, and not by Lines. This eliminates the mistakes of the programmer, for example, to get the method parameters in the wrong way - the compiler will not pick it up if both of them are strings.

+10
source

You will get a lot of support methods in case or URL. but if you just display it, then go for String, you can always create a URL from a valid string

0
source

URL , URL-, , , . URL- , .

0

All Articles