I will add this to further @assylias's answer.
If you look through the source code of InetAddress.getByName
you will notice that all it really does, is call down into InetAddress.getAllByName
. If you look at the source for that method, you will see the following towards the end:
InetAddress[] ret = new InetAddress[1];
if(addr != null) {
if (addr.length == Inet4Address.INADDRSZ) {
ret[0] = new Inet4Address(null, addr);
} else {
if (ifname != null) {
ret[0] = new Inet6Address(null, addr, ifname);
} else {
ret[0] = new Inet6Address(null, addr, numericZone);
}
}
return ret;
}
There you can see that InetAddress.getAllByName
attempts to determine what version of IP that the address is formatted as. It then instanciates an Inet4/6Address
Object based on the format of your input string.
Therefore, because you are getting either Inet4Address
or Inet6Address
, and they both have full implementations of getAddress
, you never really call the InetAddress.getAddress
method.