java-7

Why is my URI not hierarchical? [duplicate]

倖福魔咒の 提交于 2019-11-26 04:25:36
问题 This question already has an answer here: Java Jar file: use resource errors: URI is not hierarchical 6 answers I have files in resource folder. For example if I need to get file from resource folder, I do like that: File myFile= new File(MyClass.class.getResource(/myFile.jpg).toURI()); System.out.println(MyClass.class.getResource(/myFile.jpg).getPath()); I\'ve tested and everything works ! The path is /D:/java/projects/.../classes/X/Y/Z/myFile.jpg But , If I create jar file, using , Maven :

How to set -source 1.7 in Android Studio and Gradle

心已入冬 提交于 2019-11-26 03:29:48
问题 I\'m getting following error when trying to compile my project in Android Studio: Gradle: error: diamond operator is not supported in -source 1.6 I have 1.7 set as target in all project preferences I\'ve found. Also the path displayed in project SDK\'s under 1.7 SDK is correct path to java 1.7 installation. Even when I run java -version in terminal, it tells me I\'m running on java 1.7. I have tried to set JAVA_HOME env variable to this: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk

Java 7 underscore in numeric literals

断了今生、忘了曾经 提交于 2019-11-26 02:36:07
问题 When we must use a _ to separate digits in a number I don\'t understand the following case in which I can\'t use it: In positions where a string of digits is expected (as documented in the JDK7 guide here) Some examples? 回答1: You don't have to use "_", you can . And examples given in the proposal are credit card numbers, phone numbers, or simply numbers for which it makes sense to have a separator in the code. For the "In positions where a string of digits is expected" it's simply in places

Generic type inference not working with method chaining?

孤街醉人 提交于 2019-11-26 02:23:00
问题 This code compiles in Java 8 but fails to compile in Java 7: class Map<K,V> { static <K,V> Map<K,V> empty() {return null;} Map<K,V> put(K k, V v) {return null;} V get(K k) {return null;} } class A { static void f(Map<Integer,String> m){} public static void main(String[] args) { f(Map.empty()); } } It doesn\'t infer the concrete type of the Map being returned from Map.empty() : $ javac7 A.java A.java:10: error: method f in class A cannot be applied to given types; f(Map.empty()); ^ required:

Can Java 8 code be compiled to run on Java 7 JVM?

我的梦境 提交于 2019-11-26 01:37:41
问题 Java 8 introduces important new language features such as lambda expressions. Are these changes in the language accompanied by such significant changes in the compiled bytecode that would prevent it from being run on a Java 7 virtual machine without using some retrotranslator? 回答1: No, using 1.8 features in your source code requires you to target a 1.8 VM. I just tried the new Java 8 release and tried compiling with -target 1.7 -source 1.8 , and the compiler refuses: $ javac Test -source 1.8

Java 7 language features with Android

二次信任 提交于 2019-11-26 00:57:46
问题 Just wondering if anyone has tried using new Java 7 language features with Android? I know that Android reads the bytecode that Java spits out and turns it to dex. So I guess my question is can it understand the bytecode of Java 7? 回答1: If you are using Android Studio , the Java 7 language should be enabled automatically without any patches. Try-with-resource requires API Level 19+, and NIO 2.0 stuff are missing. If you can't use Java 7 features, see @Nuno's answer on how to edit your build

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

元气小坏坏 提交于 2019-11-26 00:24:41
问题 I\'m compiling a project in Eclipse using m2eclipse. I set the JDK path in Eclipse like this: Windows-->preferences-->installed jres--> jdk1.7.xx path But this is showing an error [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------

How should I use try-with-resources with JDBC?

陌路散爱 提交于 2019-11-25 23:37:11
问题 I have a method for getting users from a database with JDBC: public List<User> getUser(int userId) { String sql = \"SELECT id, name FROM users WHERE id = ?\"; List<User> users = new ArrayList<User>(); try { Connection con = DriverManager.getConnection(myConnectionURL); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, userId); ResultSet rs = ps.executeQuery(); while(rs.next()) { users.add(new User(rs.getInt(\"id\"), rs.getString(\"name\"))); } rs.close(); ps.close(); con.close();

Java error: Comparison method violates its general contract

徘徊边缘 提交于 2019-11-25 22:43:40
问题 I saw many questions about this, and tried to solve the problem, but after one hour of googling and a lots of trial & error, I still can\'t fix it. I hope some of you catch the problem. This is what I get: java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:835) at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:453) at java.util.ComparableTimSort.mergeForceCollapse(ComparableTimSort.java

What is the point of the diamond operator (<>) in Java 7?

六眼飞鱼酱① 提交于 2019-11-25 22:14:55
问题 The diamond operator in java 7 allows code like the following: List<String> list = new LinkedList<>(); However in Java 5/6, I can simply write: List<String> list = new LinkedList(); My understanding of type erasure is that these are exactly the same. (The generic gets removed at runtime anyway). Why bother with the diamond at all? What new functionality / type safety does it allow? If it doesn\'t yield any new functionality why do they mention it as a feature? Is my understanding of this