class construct
{
public static void main(String args[])
{
char chars1[]={'a','b','c'};
char chars2[]={'a','b','c','e'};
String s1=new String(chars1);
String s2=new String(chars2,0,3);
byte ascii1[]={97,98,99};
byte ascii2[]={97,98,99,100,101};
String s3=new String(ascii1, 0);
String s4=new String(ascii2, 0,0,3);
System.out.println("Value of String s1 is:     "+s1);
System.out.println("Value of String s2 is:     "+s2);
System.out.println("Value of String s3 is:     "+s3);
System.out.println("Value of String s4 is:     "+s4);
System.out.println("THEY ARE ALL\"abc\"!");
}
}我是输javac -deprecation construction.java String s3=new String(ascii1, 0);
String s4=new String(ascii2, 0,0,3);
警告的是这两行。
谢谢!

解决方案 »

  1.   

    String(byte[] ascii, int hibyte)
              Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a charset name or that use the platform's default charset.String(byte[] ascii, int hibyte, int offset, int count)
              Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a charset name or that use the platform's default charset.
    除非你不这样构造String,否则,肯定有警告
      

  2.   

    所有jdk或者第三方包中的方法的java doc有关键字Deprecated都是不建议使用的方法,肯定会有比这个方法更合理的方法。Deprecated是不建议使用的意思。