java-7

Java 7 switch statement with strings not working

拈花ヽ惹草 提交于 2019-12-05 01:23:08
According to The Java Tutorials , in Java SE 7 and later, you can use a String object in the switch statement's expression. String s = ... switch(s){ //do stuff } But is this true? I've installed the JRE and added it to the build path of my Eclipse project, but I'm getting the following compile-time error: Cannot switch on a value of type String. Only convertible int values or enum constants are permitted Also, I think I've got it configured correctly since I was able to use its java.nio.file.Files class, as well as JLayer . Any ideas? While it is true that the JDT team has implemented the

Why can't we switch on classes in Java 7+?

不问归期 提交于 2019-12-05 00:47:41
问题 It seems to me that such a switch statement would make a lot of sense, but it gives a compile error : public void m(Class c) { switch (c) { case SubClassOfC1.class : //do stuff; break; case SubClassOfC2.class : //do stuff; break; } } However, classes are not supported to switch on. What is the reason why? I am not trying to workaround instanceof , it's really at the class level that I got some operations to perform, no instances there. The compile error is around SubClassOfC1 & SubClassOfC2 :

Set ant bootclasspath: JDK 1.7 has a new javac warning for setting an older source without bootclasspath

浪尽此生 提交于 2019-12-04 23:53:27
How do I set the ant bootclasspath in conjunction with -source 1.5 -target 1.5? How can this not be a hardcoded path to the 1.5 JDK? Can I set an environment variable to bootclasspath similar to how JAVA_HOME can be used from ant? Ideally I would like to do something like set an environment variable or pass an argument to ant. Here's an illustration of how you might fetch the Java 5 boot classes location from an environment variable, then use it. First, set the environment variable - say JAVA5_BOOTCLASSES . The property task gives you access to the environment, then the bootclasspath argument

ArrayList<> vs ArrayList<Integer>

邮差的信 提交于 2019-12-04 23:31:22
What is the difference in the two following declarations of an ArrayList? ArrayList<Integer> nunbers = new ArrayList<Integer>(); vs ArrayList<Integer> nunbers = new ArrayList<>(); Is one of them preferred over the other? The second one has its type parameter inferred , which is a new thing in Java 7. <> is called " the diamond ". Also note that type inference itself is not new in Java , but the ability to infer it for the generic class being instantiated is new. Compilers from releases prior to Java SE 7 are able to infer the actual type parameters of generic constructors, similar to generic

Compile error: “'<>' cannot be used with anonymous classes” [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-04 23:14:50
This question already has answers here : Why can't Java 7 diamond operator be used with anonymous classes? (4 answers) Closed 2 years ago . I would so much rather like to write this: Lists.transform(vals, new Function<>() { public List<ValEntry> apply(Validator<? super T> input) { return input.validate(value); } }); ...than this: Lists.transform(vals, new Function<Validator<? super T>, List<ValEntry>>() { public List<ValEntry> apply(Validator<? super T> input) { return input.validate( value ); } }); But the Java compiler gives me the following error message: '<>' cannot be used with anonymous

IntelliJ compile for Java 7 JRE using Java 8 SDK

时光毁灭记忆、已成空白 提交于 2019-12-04 22:44:21
I have the Java 8 SDK and runtime, and a project that is only using Java 7 features. I was wondering whether I could set up intellij to build a Java-7-level jar, something that is definitely possible from command line? So far, I have tried simply setting the project language level to 7 as an experiment, but that is obviously insufficient and not really what I need. I have also seen this question on SO: " Intellij IDEA using java7 compiler to compile when I have configured it to use Java6 ", but my project SDK is already set up to the newest Java version, and I merely need a Java-7-compatible

Why will there be no native properties in Java 7?

故事扮演 提交于 2019-12-04 22:42:52
Is there any rational reason, why native properties will not be part of Java 7? Doing properties "right" in Java will not be easy. Rémi Forax's work especially has been valuable in figuring out what this might look like, and uncovering a lot of the "gotchas" that will have to be dealt with. Meanwhile, Java 7 has already taken too long. The closures debate was a huge, controversial distraction that wasted a lot of mind-power that could have been used to develop features (like properties) that have broad consensus of support. Eventually, the decision was made to limit major changes to

Java nio WatchService for multiple directories

核能气质少年 提交于 2019-12-04 21:14:22
问题 I want to watch (monitor) multiple directories using Java NIO WatchService. My problem here is the number of directories to watch is dynamic and the user can add any number of directories to the WatchService . Is this achievable? 回答1: It is possible to register multiple paths with the same WatchService . Each path gets its own WatchKey . The take() or poll() will then return the WatchKey corresponding to the path that was modified. See Java's WatchDir example for details. 回答2: I am just

Dozer : String-To-Date Field Level Mapping for a List

时光总嘲笑我的痴心妄想 提交于 2019-12-04 21:05:13
I want to map a DTO (all are of String Data Types) to VO (contains String,int,boolean,Date) StudentDTO private StudentDetailDTO student; StudentDetailDTO : private String sid; private String name; private String createDt; private String studentInd; private List<FeeReceiptDTO> feeDetails; FeeReceiptDTO: private String semisterNum; private String feeAmount; private String paidOn; StudentDetailVO : private int sid; private String name; private Date createDt; private boolean studentInd; private List<FeeReceiptVO> feeDetails; FeeReceiptVO: private int semisterNum; private Double feeAmount; private

Not able to understand how to define a List of List in java [duplicate]

蹲街弑〆低调 提交于 2019-12-04 19:46:50
This question already has an answer here: Incompatible types List of List and ArrayList of ArrayList 6 answers Initialize List<List<Integer>> in Java 2 answers I want to understand the difference between the two definitions and why the correct one is correct and the wrong is wrong. The one showing me the compile-error List<List<Integer>> arr2 = new ArrayList<ArrayList<Integer>>(); The error it gave me : try2.java:8: error: incompatible types: ArrayList<ArrayList<Integer>> cannot be converted to List<List<Integer>> List<List<Integer>> arr2 = new ArrayList<ArrayList<Integer>>(); The one which is