java-7

Generic class compiles in Java 6, but not Java 7

我只是一个虾纸丫 提交于 2019-11-28 08:20:31
I have an interface in Java 6 that compiles correctly: public interface IMultiMap<K, V> extends Map<K, Set<V>> { public int valueSize(); public boolean put(K key, V value); public void clear(Object key); public boolean isEmpty(Object key); } But in Java 7, this interface doesn't compile. I get a compile error on boolean put(K, V) that it has the same erasure as V put(K, V) . The full error from the compiler: error: name clash: put(K#1,V#1) in IMultiMap and put(K#2,V#2) in Map have the same erasure, yet neither overrides the other public boolean put(K key, V value); where K#1,V#1,K#2,V#2 are

Does Android plan to support Java7? [closed]

三世轮回 提交于 2019-11-28 07:59:43
As Android does not currently support java7, I find myself wondering if they have made an official comment if they are working on supporting it? I was under the impresssion that android didn't use oracle java, it uses a subset of apaches harmony java: http://en.wikipedia.org/wiki/Apache_Harmony#Use_in_Android_SDK http://arstechnica.com/open-source/news/2010/11/apache-foundation-to-vote-down-java-7-protesting-oracle-abuses.ars 来源: https://stackoverflow.com/questions/8535164/does-android-plan-to-support-java7

Compilation error with generics and ternary operator in JDK 7

馋奶兔 提交于 2019-11-28 07:34:37
问题 I ran into a compilation failure while writing some Java code, which I distilled down to the following test case: import java.util.Collections; import java.util.List; public class TernaryFailure { public static List<String> thisWorks() { return Collections.emptyList(); } public static List<String> thisFailsToCompile() { return true ? Collections.emptyList() : Collections.emptyList(); } } The code above fails to compile with javac with JDK 1.7.0_45: $ javac TernaryFailure.java TernaryFailure

Why can't Java 7 diamond operator be used with anonymous classes?

纵然是瞬间 提交于 2019-11-28 07:12:01
Consider this Java code which attempts to instantiate some List s: List<String> list1 = new ArrayList<String>(); List<String> list2 = new ArrayList<>(); List<String> list3 = new ArrayList<String>() { }; List<String> list4 = new ArrayList<>() { }; List<String> list5 = new ArrayList<Integer>() { }; list1 and list2 are straightforward; list2 uses the new diamond operator in Java 7 to reduce unnecessary repetition of the type parameters. list3 is a variation on list1 using an anonymous class, potentially to override some methods of ArrayList . list4 attempts to use the diamond operator, similar to

Are Locks AutoCloseable?

走远了吗. 提交于 2019-11-28 07:11:17
Are Locks AutoCloseable? That is, instead of: Lock someLock = new ReentrantLock(); someLock.lock(); try { // ... } finally { someLock.unlock(); } can I say: try (Lock someLock = new ReentrantLock()) { someLock.lock(); // ... } in Java 7? dlev No, neither the Lock interface (nor the ReentrantLock class) implement the AutoCloseable interface, which is required for use with the new try-with-resource syntax. If you wanted to get this to work, you could write a simple wrapper: public class LockWrapper implements AutoCloseable { private final Lock _lock; public LockWrapper(Lock l) { this._lock = l;

Java: print contents of text file to screen

故事扮演 提交于 2019-11-28 06:52:52
I have a text file named foo.txt , and its contents are as below: this is text How would I print this exact file to the screen in Java 7? Before Java 7: BufferedReader br = new BufferedReader(new FileReader("foo.txt")); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } add exception handling add closing the stream Since Java 7, there is no need to close the stream, because it implements autocloseable try (BufferedReader br = new BufferedReader(new FileReader("foo.txt"))) { String line = null; while ((line = br.readLine()) != null) { System.out.println

What kind of pitfals exist for the Android APK signing?

*爱你&永不变心* 提交于 2019-11-28 06:50:35
Disclaimer: I know the basics of signing an APKs and I have a problem with only one of my projects and only when signing with Microsoft Windows as the OS. I am building my APK with Maven and sign them with the maven-jarsigner-plugin: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jarsigner-plugin</artifactId> <executions> <execution> <id>signing</id> <goals> <goal>sign</goal> </goals> <phase>package</phase> <inherited>true</inherited> <configuration> <archive>target/${project.build.finalName}.apk</archive> <sigfile>CERT</sigfile> <keystore>${env.HOME}/.keystore<

JDK 7 class file backward compatibility with JDK 6

♀尐吖头ヾ 提交于 2019-11-28 06:48:16
Which features of JDK 7 (excluding invokedynamic because it is not used by java) causing a new class file version which is not compliant with JDK 6. It seams that all features could be implemented by compiler generating glue codes. For example String in switch statement could be implemented using repeated ifeq statements generated by the compiler. I want to able to give -source 1.7 -target 1.6 flags to compiler to be compliant with jre 6 and at the same time use project coin features in jdk 7. I haven't read the code for the compiler, but some of the new features must obviously have an impact

Error occurred during initialization of VM (java/lang/NoClassDefFoundError: java/lang/Object)

旧巷老猫 提交于 2019-11-28 06:19:19
I'm trying to install Java to use Eclipse (I followed all instructions to install Java and Eclipse) but my Eclipse is not starting due to some bad configuration I guess. I can't figure out why it's not working for me. Eclipse Installation: Extracted Eclipse at C:\eclipse Created a shortcut to my desktop having target C:\eclipse\eclipse.exe When I try to run Eclipse with this shortcut, I see following Eclipse splash screen for a second and it disappears. Eclipse does not start at all. JAVA Installation: Installed JDK at C:\Program Files\Java\jdk1.7.0_10 Installed JRE at C:\Program Files\Java

How to check the extension of a Java 7 Path

老子叫甜甜 提交于 2019-11-28 05:10:46
I'd like to check if a Path (introduced in Java 7) ends with a certain extension. I tried the endsWith() method like so: Path path = Paths.get("foo/bar.java") if (path.endsWith(".java")){ //Do stuff } However, this doesn't seem to work because path.endsWith(".java") returns false. It seems the endsWith() method only returns true if there is a complete match for everything after the final directory separator (e.g. bar.java ), which isn't practical for me. So how can I check the file extension of a Path? fan Java NIO's PathMatcher provides FileSystem.getPathMatcher(String syntaxAndPattern) :