当前页面: 开发资料首页 → J2SE 专题 → 问y 关于java import的问题(在线等)
问y 关于java import的问题(在线等)
摘要: 问y 关于java import的问题(在线等)
不废话了 Integer.toHexString
我想把Integer省掉,就要在文件最上用import
import static java.lang.Integer.toHexString;
可是javac编译时报错
CharCodeCalcs.java:1:
expected
import static java.lang.Integer.toHexString;
^
CharCodeCalcs.java:1: '.' expected
import static java.lang.Integer.toHexString;
可是我用别的类时
比如用IOException时我import
import java.io.IOException;
就不会报错
只要是import static都是这个错 是因为CLASSPATH的设置问题吗?我设的地址也没问题../lib/tools.jar
大哥,Integer.toHexString其中toHexString是Integer类的一个静态方法,import是用来引用类的,啥时候可以引方法了!
不是你的设置问题,因为toHexString是Integer的一个static方法,你可以不创建Integer的对象,就可以直接引用,所以要写成Integer.toHexString(int value)这样的形式。我的理解是这样的 有错误的地方,希望高人指出!
是你的JDK的问题吧? 这种Import是JAVA 1.5以后才支持的。
import static java.lang.Integer.toHexString;
public class CommonTest {
public static void main(String[] args) {
String str = toHexString(new Integer(113));
System.out.println(str);
}
}
我这样写,完全没有问题
to lip009(深蓝忧郁)
不要一棒子打死, 请关注一下JAVA 5的特性
汗自己...还没用过1.5
哎!又落后了...汗
我的是1.4,郁闷 我去下1.5
哈哈,我用了1.5好久,却不知道能这么用,看来白用了!
我也用的1.5 不知道可以import这东西了。。