用-Xlint重新编译:未经检查以获取详细信息 [英] Recompile with -Xlint : unchecked for details

查看:126
本文介绍了用-Xlint重新编译:未经检查以获取详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有此警告。我尝试使用

Hi guys I have this warning on my code. I try to compile using


@SuppressWarnings( unchecked)

@SuppressWarnings("unchecked")


进行编译

它可以编译,但是在执行时程序找不到主类。

It compile but at the time of the execution the program can't find the main class.

如何解决此问题?

下面的代码:

import java.util.*;

@SuppressWarnings("unchecked")

class ProgRub {
    public static void main(String argv[]) {
        Hashtable rubrica = new Hashtable(20);
        String chiave, valore;
        Menu mioMenu = new Menu();
        int scelta;
        scelta = (int) mioMenu.scelta();

        while (scelta != 5) {
            if (scelta == 1) {
                chiave = mioMenu.leggiDato("Nome:");
                valoe = mioMenu.leggiDato("Valore:");
                rubrica.put(chiave, valore);
            } else if (scelta == 2) {
                chiave = mioMenu.leggiDato("Nome:");
                rubrica.remove(chiave);
            } else if (scelta == 3) {
                Iterator i = rubrica.keySet().iterator();
                while (i.hasNext()) {
                    chiave = (String) i.next();
                    valore = (String) rubrica.get(chiave);
                    System.out.println(chiave + "tel." + valore);
                }
            }

            else if (scelta == 4) {
                chiave = mioMenu.leggiDato("Nome:");
                if (rubrica.contains(chiave)) {
                    valore = (String) rubrica.get(chiave);
                    System.out.println("Telefono:" + valore);
                }

                else {
                    System.out.println("Nominativo inesistente.");
                }
            }
            scelta = (int) mioMenu.scelta();
        }

        System.out.println("Fine programma.");
    }
}


推荐答案

您使用 Hashtable Iterator 作为原始类型。如果您分别将它们用作 Hashtable< String,String> Iterator< String>

You are using Hashtable and Iterator as raw types. If you use them as Hashtable<String, String> and Iterator<String> respectively:


  • 您不必抑制未经检查的警告,并且

  • 您可以摆脱一堆类型转换

要了解更多信息,建议您花些时间阅读Java泛型:

To understand more, I recommend that you take the time to read up on Java generics:

  • https://docs.oracle.com/javase/tutorial/java/generics/index.html

这篇关于用-Xlint重新编译:未经检查以获取详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆