Why do the InetAddress, Inet4Address, and Inet6Address classes have no visible constructors?
Why do the InetAddress , Inet4Address , and Inet6Address classes have no visible constructors?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because it’s a factory class. Using static methods to return a factory instance makes sense when there are a small number of situations in which you will want to create such an object.
So, instead of overloading the constructor to the point where you’ll have to remember all sorts of bizarre combinations of arguments to use for each given situation, it just gives you one (hopefully well-named) method per situation.
In this case, you can create an object with one of:
getLocalHost(), getting your own address;getByName(), getting the “primary” address for a site; orgetAllByName(), getting a list of the addresses.This isn’t an exhaustive list, see here for more of them, search that page for: