javac

Trouble with -Xlint:all and maven

空扰寡人 提交于 2019-12-04 14:04:49
问题 I'm trying to get maven to output lint level warnings. I've created a small test program that should generate a warning about using a static method from a non-static context, but despite a number of different plugin configuration options, the build always succeeds without any warnings! After doing some googling, I found suggestions to use the 'compilerArgument(s)' attribute of the compiler plugin, but this doesn't seem to be working for me either. Here's my sample program that should generate

Java Classes: Anonymous vs Nested vs Private

淺唱寂寞╮ 提交于 2019-12-04 12:22:03
Can someone explain the difference between anonymous classes, nested classes and private classes in Java? I'd like to know the runtime costs associated with each and the compiler approach to each, so I can get a grip on which is best to use for e.g. performance (potential for compiler optimisations), memory usage, and general acceptability with other Java coders. By anonymous classes I mean those declared inline in a function in that weird Java way. This is often seen in examples of Swing code where you write a button handler inline with the declaration of it. I don't really like anonymous

Java 8 Incompatible Types

牧云@^-^@ 提交于 2019-12-04 12:02:35
Here's the simple code import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class SimpleTest { public static void main(String[] args) { final ArrayList<Map<String, Object>> maps = newArrayList( createMap("1", "a", Collections.EMPTY_MAP, Collections.EMPTY_MAP), createMap("2", "b", Collections.EMPTY_MAP, Collections.EMPTY_MAP), createMap("3", "c", Collections.EMPTY_MAP, Collections.EMPTY_MAP) ); System.out.println(" maps = " + maps); } public static Map<String, Object> createMap(String value1, String value2, Map<String, Object> object1,

import class file in java [closed]

浪子不回头ぞ 提交于 2019-12-04 11:52:42
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have a main directory (contains main.java) and a subdirectory( contains child.java). My problem is how to instantiate child.java in main.java I have

unable to use an intersection type when notional class requires access modification

对着背影说爱祢 提交于 2019-12-04 06:31:39
Interfaces: interface PublicCloneable { Object clone(); } interface HasPosition { // doesn't matter } Attempt to use intersection type: @SuppressWarnings("unchecked") <E extends PublicCloneable & HasPosition> E cloneAndIncrementPosition(E elem) { final E clone = (E)elem.clone(); // rest omitted } Attempt to compile with javac 1.8.0_60 : $ javac xx.java xx.java:13: error: clone() in Object cannot implement clone() in PublicCloneable <E extends PublicCloneable & HasPosition> E cloneAndIncrementPosition(E elem) { ^ attempting to assign weaker access privileges; was public xx.java:14: error: clone

why is this code not compiling with javac but has no errors in eclipse?

大兔子大兔子 提交于 2019-12-04 05:57:14
the following code: @Retention(RetentionPolicy.RUNTIME) @Target( { ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE }) @Constraint(validatedBy = { MinTimeIntCoConstraintValidator.class, MinTimeIntCoListConstraintValidator.class, MinTimeDoubleCoConstraintValidator.class, MinTimeDoubleCoListConstraintValidator.class, }) @Documented public @interface MinTimeValueCo { int value(); String message() default "value does not match minimum requirements"; Class<?>[] groups() default { }; Class<? extends Payload>[] payload() default {}; } compiled in eclipse but fails to compile in sun

Creating a batch file, for simple javac and java command execution

天涯浪子 提交于 2019-12-04 03:41:53
It is a really simple thing but I cannot get my head around it. I have looked at plenty of StackOverFlow post and as well as on internet. My goal is to create a .bat which will open cmd and execute my Main.java into command prompt. Easy isn't it, but I have got confused about how? Below I am writing steps which my batch file should perform open cmd javac Main.java java Main My file will reside next to all my .java so I am assuming I don't need to give explicit path. My understanding so far by research: open text editor write a code to open cmd(Which I am not sure how) echo javac Main.java

Exporting a package from system module is not allowed with --release

天涯浪子 提交于 2019-12-04 02:23:09
I have the following program: module-info.java module a { } Main.java public class Main { public static void main(String[] args) { System.out.println(sun.nio.ByteBuffered.class); } } This program successfully compiles with the --add-exports option: > javac --add-exports java.base/sun.nio=a module-info.java Main.java However, when I add the --release argument, it fails: > javac --add-exports java.base/sun.nio=a --release 9 module-info.java Main.java error: exporting a package from system module java.base is not allowed with --release 1 error Basically, these two commands are equivalent. So why

(JAVA) Use Command Prompt to create .jar file from multiple .class files

让人想犯罪 __ 提交于 2019-12-04 01:13:42
问题 I have written a .java file, called Main.java, and have compiled it using the javac in the Windows Command Prompt. The compiler is creating multiple .class files (called Main.class, Main$1.class, & Main$2.class--presumably because I have anonymous inner classes in my Main.java file). I am trying to create a runnable .jar file so I can double click a shortcut to run this application (it is a Java Swing application), but I am unsuccessful when I navigate to the directory of the three class

Set JDK home (javac path) in user's gradle.properties

流过昼夜 提交于 2019-12-03 21:33:31
I need to specify the path to javac in my gradle project. I can do this by adding the following to my build.gradle file: options.forkOptions.executable = '/home/mj/lib/jdk1.7.0_80/bin/javac' The problem is that this file is shared in our repository and I do not want the setting to get pushed there. I tried putting it in my local gradle.properties file, but it didn't work. Also setting gradle.java.home does not affect this. I guess it's because gradle uses gradle.java.home for java and not for javac , right? I also (hopelessly) tried setting a gradle.jdk.home which (not surprisingly) didn't