I need to create an URL based on the port number by using java.net.url class's constructor. To do that I've used the constructor below,
public URL(String protocol, String host, int port, String file){}
I need to create two different URL; if the port is 80, need to ignore the port, else URL should contain the port number. I'm not able to send port number as null, there is a value which is -1. When I use -1 for port, it creates the URL without port.
My problem is documentation of constructor; above of the constructor there is a description and that decription is "Specifying a {@code port} number of {@code -1} indicates that the URL should use the default port for the protocol.". As I mentioned, I don't want to use default port number. If that is the case, how can I create a URL only with a such constructor?
BTW, I know, I could use only String version, I don't want to write two new URL to do that. Basically, I want to write something like this,
new URL(scheme, serverName, serverPort == 80 ? -1 : serverPort, contextPath); // as I mentioned based on the documentation of URL constructor, -1 gets the default port number, but in the code it is not like that.
Waiting for your suggestions. Thank you.
EDIT
new URL(scheme, serverName, serverPort == 80 ? null: serverPort, contextPath);