javac

javac error: inconvertible types with generics?

懵懂的女人 提交于 2019-12-18 10:34:25
问题 There are several other SO questions talking about generics compiling OK w/ Eclipse's compiler but not javac (i.e. Java: Generics handled differenlty in Eclipse and javac and Generics compiles and runs in Eclipse, but doesn't compile in javac) -- however this looks like a slightly different one. I have an enum class: public class LogEvent { public enum Type { // ... values here ... } ... } and I have another class with a method that takes in arbitrary objects of types descended from Enum :

In Java 8, why were Arrays not given the forEach method of Iterable?

眉间皱痕 提交于 2019-12-18 10:12:27
问题 I must be missing something here. In Java 5, the "for-each loop" statement (also called the enhanced for loop) was introduced. It appears that it was introduced mainly to iterate through Collections . Any collection (or container) class that implements the Iterable interface is eligible for iteration using the "for-each loop". Perhaps for historic reasons, the Java arrays did not implement the Iterable interface. But since arrays were/are ubiquitous, javac would accept the use of for-each

javac : command not found

自作多情 提交于 2019-12-18 10:02:30
问题 I have installed java in my CentOS release 5.5 machine using the command yum install java . But I am unable to compile a class using javac. Do I need to install any other package? I have tried to locate the javac executable but i am unable to locate it. /usr/bin/java is linked as follows: /usr/bin/java -> /etc/alternatives/java /etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java I have seen the following output by yum list installed |grep java : java-1.6.0-openjdk.x86_64

JAVA: missing return statement

不想你离开。 提交于 2019-12-18 09:49:35
问题 my main concern with this code as of right now is a missing return statement. public class stringstuff{ //using charAt public static String ReverseF(String n){ String finalstring = ""; int len = n.length(); for (int i = 0; (i < n.length()); i++){ finalstring += (n.charAt(len - i - 1)); } System.out.println(finalstring); } public static void main(String[]args){ ReverseF("Hello"); } } Using this code I only get the error: stringstuff.java:11: missing return statement } ^ 1 error If I switch the

Java error: class, interface, or enum expected

梦想的初衷 提交于 2019-12-18 08:56:10
问题 I need to know the output of this code. But it's not working. Maybe the code is wrong. I'm still learning how to use Java, and I tried fixing this for hours but still no luck. Here is the code: public class A { public A() { System.out.println ("A"); } } public class B extends A { public B() { System.out.println ("B"); } } public class C extends B { public C() { System.out.println ("C"); } } public static void main(String args[]) { A a = new A(); B b = new B(); C c = new C(); } Can anyone tell

Target different version of JRE

依然范特西╮ 提交于 2019-12-17 21:29:04
问题 I'm testing Java on a Windows Surface Pro. The Surface Pro has Java 7 Update 55, but does not have the JDK installed. I compiled a program on my MacBook from the command line using javac . The MacBook Has Java 8 Update 5 and it includes the JDK (obviously because I compiled on the MBP). When I move the program from the MackBook to the Surface Pro, I get the following error. Here, "moving the program" means copying the two *.class files to the new machine and trying to execute the byte codes.

javac classpath option with multiple jar files in current directory causing error

六月ゝ 毕业季﹏ 提交于 2019-12-17 20:21:55
问题 Environment: Windows 7, Java 6. Trying to compile a .java file with -cp option. The file uses a single jar file that's in the current directory ALONG WITH some other jar files in the current directory. javac -cp ./*.jar MyFile.java doesn't work. javac -cp ./* MyFile.java doesn't work javac -cp ./MyJar.jar MyFile.java works First two cases, I get a invalid flag error. Can someone explain this behavior? And I checked if it is spaces issue, there are no spaces anywhere in my full file paths. 回答1

javac cannot be run, and furthermore does not seem installed

橙三吉。 提交于 2019-12-17 20:09:18
问题 I have a problem involving setting up Java. I have installed the JRE, added its path to PATH , and set JAVA_HOME and CLASSPATH . Now, java and javacpl work fine, but running javac generates a command-not-found error. Furthermore, javac.exe does not even seem to exist in the JRE's bin folder. How do I run javac ? 回答1: The JRE is merely the Java Runtime Environment , which includes only the infrastructure needed to run Java programs that are already compiled. To compile Java source code using

Which JDK's distributions can run `javac -source 1.6 -target 1.5`?

*爱你&永不变心* 提交于 2019-12-17 16:41:55
问题 NOTE: Please do not comment on all the perils of cross-compiling. Thank you. I have a situation where we need to have Java 6 source compiled for a Java 5 JVM (to be sure that JAX-WS usage is correct). Previously we have done this with ant ant script (which apparently can), but after migrating to Maven we have found that it ends up with javac complaining: $ javac -source 1.6 -target 1.5 javac: source release 1.6 requires target release 1.6 Is there any Java distribution for Linux (Ubuntu 11.10

Javac flag to disallow raw types?

孤人 提交于 2019-12-17 16:34:31
问题 Is there any Java compiler flag that one can pass to tell the compiler to disallow the use of raw types? That is, for any generic class, let the compiler force that the parameterized version be used, and throw a compilation error otherwise? 回答1: JDK7 (b38) introduces -Xlint:rawtypes. As mentioned above, -Xlint:unchecked warns about unchecked conversions. Maurizio Cimadamore of the javac team wrote a weblog entry about it. 回答2: You can configure the use of raw types within Eclipse to be a