toString()是个非static方法,也就是说你调用它,必须用实例调用
而不是类名调用的static方法.
InetAddress这个东东没用过,如果他是一个类的话,
InetAddress netAddress = new InetAddress();
netAddress.toString();
这样应该是合法的.
而不是类名调用的static方法.
InetAddress这个东东没用过,如果他是一个类的话,
InetAddress netAddress = new InetAddress();
netAddress.toString();
这样应该是合法的.
如 String.valueOf(char c);
import java.net.UnknownHostException;public class a{
public static void main(String [] args)throws Exception{
System.out.println(InetAddress.getLocalHost().toString());
}
}
注意:InetAddress 是不可以用 new 来创建对象,即其不提供你构造函数,这种做法在Java中很普遍.限制用户按其设置创建对象.
你只能使用:
InetAddress.getAllByName(
InetAddress.getByAddress(
InetAddress.getByAddress(
InetAddress.getByName(
InetAddress.getLocalHost(
这几类InetAddress提供的静态方法来创建对象.然后再调用其.toString()方法.
难道说东西已存在只是java对象化了???
====================================同意