当前位置:  开发笔记 > 编程语言 > 正文

如何使Java语法正确?

如何解决《如何使Java语法正确?》经验,为你挑选了1个好方法。

我编译程序后得到一堆警告声明,我知道我可以关闭它们,但我想让它们正确,但我不知道正确的方法来修复它们,因为它们中的一些抱怨方式,像这样:

BS=(TreeSet)B.next()
BS=(TreeSet)B.next()


有什么帮助吗?这里是其中的一些 :

170: warning: [unchecked] unchecked call to getMethod(java.lang.String,java.lang.Class...) as a member of the raw type java.lang.Class
        Method createMethod=factory.getMethod("create"+currentValue, parameters);
---------------------------------------------------------------------------------------------------------------------------------
168        Class factory=Class.forName("net.sourceforge.barbecue.BarcodeFactory");
169        Class [] parameters={ "".getClass() };
170        Method createMethod=factory.getMethod("create"+currentValue, parameters);
=======================================================================================================
76: warning: [unchecked] unchecked conversion
found   : java.util.Vector[]
required: java.util.Vector[]
  static Vector Region[]=new Vector[Nm_Lib.Region_Num];
---------------------------------------------------------------------------------------------------------------------------------
76        static Vector Region[]=new Vector[Nm_Lib.Region_Num];
=======================================================================================================
1365: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.Vector
        Loaded_Contact_Info_Entry_Vector=(Vector)XML_Decoder.readObject();
---------------------------------------------------------------------------------------------------------------------------------
1358    Vector Loaded_Contact_Info_Entry_Vector=new Vector();
1359    
1360    if (new File(A_Path).exists())
1361      try
1362      {
1363//        Out("A_Path="+A_Path);
1364        XML_Decoder=new XMLDecoder(new BufferedInputStream(new FileInputStream(A_Path)));
1365        Loaded_Contact_Info_Entry_Vector=(Vector)XML_Decoder.readObject();
=======================================================================================================
1902: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.Vector
      if (textToUse == FILE_TEXT) backupLineBreakTLs=(Vector) lineBreakTLs.clone();
---------------------------------------------------------------------------------------------------------------------------------
1692    private Vector lineBreakTLs=null;
1693    for (int i=0; i < fileText.length; i++)
1694    {
1695      AttributedString as=new AttributedString(fileText[i],g2.getFont().getAttributes());
1696      LineBreakMeasurer lbm=new LineBreakMeasurer(as.getIterator(),g2.getFontRenderContext());
1697      while (lbm.getPosition() < fileText[i].length()) lineBreakTLs.add(lbm.nextLayout((float) w));
1698    }
......
1901    Vector backupLineBreakTLs=null;
1902    if (textToUse == FILE_TEXT) backupLineBreakTLs=(Vector) lineBreakTLs.clone();
=======================================================================================================
143: warning: [unchecked] unchecked conversion
found   : java.util.TreeSet
required: java.util.TreeSet
          BS=(TreeSet)B.next();
---------------------------------------------------------------------------------------------------------------------------------
139          TreeSet Sub_Set=new TreeSet(TreeSet_Order);
140          Sub_Set.add(First);
141          if (Debug) System.out.println("=7.20= Sub_Set="+Sub_Set);
142          TreeSet BS=new TreeSet(TreeSet_Order);
143          BS=(TreeSet)B.next();
=======================================================================================================
813: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.Vector
    Vector dataRow=(Vector)rows.elementAt(row);
---------------------------------------------------------------------------------------------------------------------------------
813    Vector dataRow=(Vector)rows.elementAt(row);
=======================================================================================================
199: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.Vector
        comboModel=(Vector)(ois.readObject());
---------------------------------------------------------------------------------------------------------------------------------
19  private static Vector comboModel;
......
199        comboModel=(Vector)(ois.readObject());
=======================================================================================================
71: warning: [unchecked] unchecked conversion
found   : LoadLibraryAction
required: java.security.PrivilegedAction
  static { java.security.AccessController.doPrivileged(new LoadLibraryAction("jpeg")); }
71: warning: [unchecked] unchecked method invocation: doPrivileged(java.security.PrivilegedAction) in java.security.AccessController is applied to (LoadLibraryAction)
  static { java.security.AccessController.doPrivileged(new LoadLibraryAction("jpeg")); }
---------------------------------------------------------------------------------------------------------------------------------
70  // load the jpeg lib when created.
71  static { java.security.AccessController.doPrivileged(new LoadLibraryAction("jpeg")); }
=======================================================================================================
184: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: java.util.Vector
      trans_frame.Events_Vector=(Vector)s.readObject();   
---------------------------------------------------------------------------------------------------------------------------------
183      ObjectInputStream s=new ObjectInputStream(in);
184      trans_frame.Events_Vector=(Vector)s.readObject();    
=======================================================================================================
3473: warning: [unchecked] unchecked call to getConstructor(java.lang.Class...) as a member of the raw type java.lang.Class
      java.lang.reflect.Constructor constructor=cl.getConstructor(new Class[] {String.class});     // get the constructor with one parameter
---------------------------------------------------------------------------------------------------------------------------------
3473      java.lang.reflect.Constructor constructor=cl.getConstructor(new Class[] {String.class});     // get the constructor with one parameter
=======================================================================================================
3476: warning: [unchecked] unchecked call to getMethod(java.lang.String,java.lang.Class...) as a member of the raw type java.lang.Class
      java.lang.reflect.Method objMethod=cl.getMethod(Method_Name,arguments);                      // get the method
---------------------------------------------------------------------------------------------------------------------------------
3475      Class  arguments[]=new Class[] { };                                                          // the method has no argument
3476      java.lang.reflect.Method objMethod=cl.getMethod(Method_Name,arguments);                      // get the method
=======================================================================================================
486: warning: [unchecked] unchecked call to getConstructor(java.lang.Class...) as a member of the raw type java.lang.Class
              Constructor ctor=cls.getConstructor(new Class[]{String.class});
---------------------------------------------------------------------------------------------------------------------------------
485              Class cls=Class.forName(loader);
486              Constructor ctor=cls.getConstructor(new Class[]{String.class});
=======================================================================================================
476: warning: [unchecked] unchecked method invocation: doPrivileged(java.security.PrivilegedAction) in java.security.AccessController is applied to ()
    JarClassLoader bootLoader=(JarClassLoader)AccessController.doPrivileged(
---------------------------------------------------------------------------------------------------------------------------------
476    JarClassLoader bootLoader=(JarClassLoader)AccessController.doPrivileged(
=======================================================================================================
224: warning: [unchecked] unchecked method invocation: sort(java.util.List) in java.util.Collections is applied to (java.util.List)
      Collections.sort(sortedModel);
---------------------------------------------------------------------------------------------------------------------------------
24  private List sortedModel;
105    sortedModel=new ArrayList(size);
224      Collections.sort(sortedModel);
=======================================================================================================
325: warning: [unchecked] unchecked conversion
found   : java.util.List
required: java.util.List>
      insertionPoint=Collections.binarySearch((List)sortedModel,entry);
---------------------------------------------------------------------------------------------------------------------------------
320  private int findInsertionPoint(SortedListEntry entry)
321  {
322    int insertionPoint=sortedModel.size();
323    if (sortOrder != SortOrder.UNORDERED)
324    {
325      insertionPoint=Collections.binarySearch((List)sortedModel,entry);
=======================================================================================================
361: warning: [unchecked] unchecked call to compare(T,T) as a member of the raw type java.util.Comparator
      int comparison=comparator.compare(thisElement, thatElement);
---------------------------------------------------------------------------------------------------------------------------------
348    public int compareTo(Object o)
349    {
350      // retrieve the element that this entry points to in the original model
351      Object thisElement=unsortedModel.getElementAt(index);
352      SortedListEntry thatEntry=(SortedListEntry)o;
353      // retrieve the element that thatEntry points to in the original model
354      Object thatElement=unsortedModel.getElementAt(thatEntry.getIndex());
355      if (comparator instanceof Collator)
356      {
357        thisElement=thisElement.toString();
358        thatElement=thatElement.toString();
359      }
360      // compare the base model's elements using the provided comparator
361      int comparison=comparator.compare(thisElement, thatElement);
=======================================================================================================
3201: warning: [unchecked] unchecked method invocation: sort(T[],java.util.Comparator) in java.util.Arrays is applied to (java.io.File[],)
    Arrays.sort(files,new Comparator() { public int compare(final Object o1,final Object o2) { return By_Ascending_Date?new Long(((File)o1).lastModified()).compareTo(new Long(((File) o2).lastModified())):new Long(((File)o2).lastModified()).compareTo(new Long(((File) o1).lastModified())); } });
---------------------------------------------------------------------------------------------------------------------------------
3197  public static File[] Get_File_List_From_Dir_By_Date(String Dir,final boolean By_Ascending_Date)
3198  {
3199    if (!new File(Dir).isDirectory()) return null;
3200    File files[]=new File(Dir).listFiles();
3201    Arrays.sort(files,new Comparator() { public int compare(final Object o1,final Object o2) { return By_Ascending_Date?new Long(((File)o1).lastModified()).compareTo(new Long(((File) o2).lastModified())):new Long(((File)o2).lastModified()).compareTo(new Long(((File) o1).lastModified())); } });

Kees de Koot.. 8

你应该阅读泛型.Angelika Langer的网站是一个很好的资源.



1> Kees de Koot..:

你应该阅读泛型.Angelika Langer的网站是一个很好的资源.

推荐阅读
夏晶阳--艺术
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有