java-7

Java generics SuppressWarnings(“unchecked”) mystery

杀马特。学长 韩版系。学妹 提交于 2019-12-04 18:57:56
问题 Why does code alternative(1) compile without warnings, and code alternative(2) produce an "unchecked cast" warning? Common for both: class Foo<T> { Foo( T [] arg ) { } } Alternative (1): class Bar<T> extends Foo<T> { protected static final Object [] EMPTY_ARRAY = {}; @SuppressWarnings("unchecked") Bar() { super( (T []) EMPTY_ARRAY ); } } Alternative (2): class Bar<T> extends Foo<T> { @SuppressWarnings("unchecked") Bar() { super( (T []) EMPTY_ARRAY ); } protected static final Object [] EMPTY

Whats the Efficient way to call http request and read inputstream in spark MapTask

浪尽此生 提交于 2019-12-04 18:55:01
Please see the below code sample JavaRDD<String> mapRDD = filteredRecords .map(new Function<String, String>() { @Override public String call(String url) throws Exception { BufferedReader in = null; URL formatURL = new URL((url.replaceAll("\"", "")) .trim()); try { HttpURLConnection con = (HttpURLConnection) formatURL .openConnection(); in = new BufferedReader(new InputStreamReader(con .getInputStream())); return in.readLine(); } finally { if (in != null) { in.close(); } } } }); here url is http GET request. example http://ip:port/cyb/test?event=movie&id=604568837&name=SID&timestamp_secs

Old projects compatible with Java 7

强颜欢笑 提交于 2019-12-04 17:53:39
问题 My old projects use Java 6 (1.6), and I don't know when I update (Java 7), they can run fine ? 回答1: There is an official list of known incompatibilities between java 6 and java 7 from Oracle (including descriptions of both binary and source-level incompatibilities in public APIs). Also you can look at the independent analysis of API changes in the Java API Tracker project: http://abi-laboratory.pro/java/tracker/timeline/jre/ The report is generated by the japi-compliance-checker tool. 回答2:

How is multi-catch implemented in Java 7?

岁酱吖の 提交于 2019-12-04 17:47:30
问题 How is the Java 7 compiler handling multi-catch blocks ? A naive implementation would be to generate bytecode as if multiple catch blocks are present. However, I have gathered from multiple source that this is not the case - A catch block that handles multiple exception types contributes no duplicate bytecode during compilation. So, how does it work ? Is there a new bytecode instruction that tells the JVM about multi-catch blocks ? 回答1: Based on the Java Virtual Machine Specification,

Binary Java 7 for Mac

我的梦境 提交于 2019-12-04 17:04:15
问题 Is there any binary release of Java 7 (using the Mac/BSD-port project) anywhere? Some blogs (e.g. Building Java 7 on Mac OS X) have a detailed instructions to build the jdk from source, but I was hoping that someone have a binary of it available for download. The problem with the instructions is that it's quite annoying to get all the version numbers correct, and slight variations might lead to wasted hours of work. 回答1: This just got released by Oracle: http://jdk7.java.net/macportpreview/

Java applet won't run under JRE7, no error displayed in console

随声附和 提交于 2019-12-04 14:55:40
Under Windows 7, 64-bit, since upgrading to JRE-7 32-bit, under IE9 32-bit or Chrome, I can't run applets such as this one . Inside the Applet rectangle, I see the message "Error. Click for details" Clicking on the applet box (blank) leads to a dialogue box: Application Error DrawingLines.class There was an error while executing the application. Click "Details" for more information. Clicking "Details" button opens the Java console, but there are no errors, just Java Plug-in 10.3.0.5 Using JRE version 1.7.0_03-b05 Java HotSpot(TM) Client VM User home directory = C:\Users\Blah ------------------

Using FileChannel to fsync a directory with NIO.2

杀马特。学长 韩版系。学妹 提交于 2019-12-04 14:43:32
I just discovered that with NIO.2, at least under Linux, I can open a FileChannel on a directory, and calling force(true) calls fsync() on the underlying file descriptor. Without getting into whether this should be necessary , it's nice to finally have this functionality available in pure Java. I haven't been able to find anywhere that this behaviour is documented, though. Can I count on this working on all Unix platforms, in future versions of Java, and in non-Oracle JVMs? See the following thread: http://mail.openjdk.java.net/pipermail/nio-dev/2015-May/003140.html It was not technically

SecondaryLoop instead of SwingWorker?

≡放荡痞女 提交于 2019-12-04 13:27:52
问题 From the documentation for SecondaryLoop, it is not clear when you should use this new feature instead of a SwingWorker, a few examples of interesting cases would be useful. 回答1: The intent of SecondaryLoop is basically the same as SwingWorker. However, using SecondaryLoop can be less hairy than chaining together multiple SwingWorkers. Take a look at Hidden Java 7 Features – SecondaryLoop for a detailed explanation & example. 来源: https://stackoverflow.com/questions/10196809/secondaryloop

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,

Unable to load class 'com.google.gson.JsonObject'

给你一囗甜甜゛ 提交于 2019-12-04 11:06:09
I am trying to include firebase SDK in my Android Studio Project. But it giving me an error. I am using latest JDK version (1.7.0_71) and it is asking for upgrading higher version to (1.7.0_67). I need help for basic firebase setup SDK on android. I tried to setup it by the reference of following link: https://firebase.google.com/docs/android/setup#add_the_sdk . I am getting following error: Please check attached screenshot I had the same problem trying to GCM to an old android project. The solution for me was to also add classpath 'com.android.tools.build:gradle:2.1.2' to the top-level build