¿Cómo compilo con-Xlint: unchecked?


Recibo un mensaje cuando compilo mi código:

Note: H:\Project2\MyGui2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

¿Cómo recompilo con -Xlint:unchecked?

Author: Etienne Perot, 2011-11-21

10 answers

Especifíquelo en la línea de comandos para javac:

Javac-Xlint: unchecked

O si estás usando Ant modifica tu objetivo javac

  <javac ...>
    <compilerarg value="-Xlint"/>
  </javac> 

Si está utilizando Maven, configure esto en el maven-compiler-plugin

<compilerArgument>-Xlint:unchecked</compilerArgument>
 37
Author: sudocode,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-05 17:55:08

Para IntelliJ 13.1, ir a Archivo -> Configuración -> Configuración del Proyecto -> Compilador -> Compilador de Java, y en el lado derecho, para Additional command line parameters introduce "-Xlint:unchecked".

 38
Author: Brian Burns,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-03 15:40:12

Sé que suena raro, pero estoy bastante seguro de que este es tu problema:

En algún lugar de MyGui.java está utilizando una colección genérica sin especificar el tipo. Por ejemplo, si está utilizando una ArrayList en algún lugar, está haciendo esto:

List list = new ArrayList();

Cuando deberías estar haciendo esto:

List<String> list = new ArrayList<String>();
 16
Author: Andrew Rasmussen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-21 17:22:09

En el proyecto gradle, puedes agregar este parámetro de compilación de la siguiente manera:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked"
    }
}
 12
Author: xianlinbox,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-04 10:27:57

Hay otra manera para gradle:

compileJava {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
 11
Author: tarn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-05 09:05:09

En CMD, escriba:

javac -Xlint:unchecked MyGui2.java

Mostrará la lista de operaciones no verificadas o inseguras.

 3
Author: Himanshu Aggarwal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-18 19:09:23

Si trabaja con un IDE como NetBeans, puede especificar la opción de compilador Xlint:unchecked en las propiedades de su proyecto.

Simplemente vaya a la ventana proyectos, haga clic derecho en el proyecto y luego haga clic en Properties.

En la ventana que aparece busque la categoría Compiling, y en el cuadro de texto etiquetado Additional Compiler Options establezca la opción Xlint:unchecked.

Por lo tanto, la configuración permanecerá establecida cada vez que compile el proyecto.

 2
Author: Josue,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-21 13:30:02

Una forma más limpia de especificar los argumentos del compilador de Gradle sigue:

CompileJava.opcion.compilerArgs = ['- Xlint: unchecked','-Xlint:deprecation']

 1
Author: Jim H,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-02 00:25:37

Otra forma de compilar usando-Xlint: sin marcar a través de la línea de comandos

Javac abc.java-Xlint: unchecked

Mostrará las advertencias no marcadas e inseguras.

 0
Author: deepak jaiswal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-16 12:07:51

Para tu información llegar a estos ajustes ha cambiado para IntelliJ 15, ¡nuevo y mejorado para un entierro aún más profundo!

Ahora es: File > Other Settings > Default Settings > 'Build, Execution, Deployment' > Compiler > Java Compiler

Y en parámetros adicionales de la línea de comandos, igual que antes, escriba "-Xlint:unchecked".

 0
Author: HAKitz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-05 10:52:51