Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: URL or String?

Is there any merit (coding style, OOP best practice, etc.) in working with an instance of java.net.URL as opposed to java.lang.String when I can be reasonably certain that a URL is valid anyway (perhaps I've specified it statically in a properties file) and I will just be working with it in its string form anyway (for example printing it in a JSP file)?

like image 637
Christoph Wurm Avatar asked Jun 21 '11 10:06

Christoph Wurm


1 Answers

java.net.URL's equals is broken. You should use java.net.URI. You should pass objects around whenever possible rather than Strings. It saves programmer errors, for example getting method parameters the wrong way round - the compiler won't pick it up if they're both Strings.

like image 56
artbristol Avatar answered Sep 28 '22 06:09

artbristol