java-7

Null-safe Method invocation Java7

风格不统一 提交于 2019-11-30 09:11:01
I want to get details about this feature of Java7 like this code public String getPostcode(Person person) { if (person != null) { Address address = person.getAddress(); if (address != null) { return address.getPostcode(); } } return null; } Can be do something like this public String getPostcode(Person person) { return person?.getAddress()?.getPostcode(); } But frankly its not much clear to me.Please explain? Null-safe method invocation was proposed for Java 7 as a part of Project Coin, but it didn't make it to final release. See all the proposed features, and what all finally got selected

Circular Progress Bar for Java Swing not working

╄→гoц情女王★ 提交于 2019-11-30 08:42:45
问题 i've discovered this test project from Oracle site because i want to add a circular progress bar in my project. I'm developing the application with Netbeans, and when i start the application, the JPanel where the circle should be.... disappaer. I've removed all the code that is not useful to solve this problem and i've got this code: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyChangeEvent; import javax.swing.*; import

Ambiguous method in Java 8, why? [duplicate]

南楼画角 提交于 2019-11-30 08:24:28
This question already has an answer here: Java type inference: reference is ambiguous in Java 8, but not Java 7 2 answers public static void main(String... args){ then(bar()); // Compilation Error } public static <E extends Exception> E bar() { return null; } public static void then(Throwable actual) { } public static void then(CharSequence actual) { } Compilation result (from command line javac Ambiguous.java ) Ambiguous.java:4: error: reference to then is ambiguous then(bar()); ^ both method then(Throwable) in Ambiguous and method then(CharSequence) in Ambiguous match 1 error Why this method

Is the OpenJDK JVM the same as the Oracle Java SE JVM?

拥有回忆 提交于 2019-11-30 08:14:05
I understand that the Oracle Java SE contains closed source extensions and tools that are not part of the OpenJDK however is the Oracle Java SE JVM identical to the OpenJDK JVM or does Oracle make changes to the OpenJDK JVM before releasing it as a Java SE JVM? Update 1: I found some info from the JDK7 updates projects: http://openjdk.java.net/projects/jdk7u/qanda.html Will the 7 Update Project receive security fixes from Oracle? Yes. As with OpenJDK 6, security fixes are first kept confidential and applied to a private forest before being pushed to the public forest as part of the general

Regular Expression named capturing groups support in Java 7

扶醉桌前 提交于 2019-11-30 08:13:48
Since Java 7 regular expressions API offers support for named capturing groups. The method java.util.regex.Matcher.group(String) returns the input subsequence captured by the given named-capturing group, but there's no example available on API documentations. What is the right syntax to specify and retrieve a named capturing group in Java 7? nhahtdh Specifying named capturing group Use the following regex with a single capturing group as an example ([Pp]attern) . Below are 4 examples on how to specify a named capturing group for the regex above: (?<Name>[Pp]attern) (?<group1>[Pp]attern) (?

Switch ignore case in java 7

感情迁移 提交于 2019-11-30 08:07:17
I am doing a POC on Java 7 new features. I have code to use String in switch statement and it works. I want to make it work in case insensitive also. Is there a way to check out with ignoreCase on String? package com.java.j7; public class Test { final private String _NEW ="NEW"; final private String _PENDING = "PENDING"; final private String _CLOSED = "CLOSED"; final private String _REJECTED ="REJECTED"; public static void main(String... strings){ Test j = new Test(); j.processItem("new"); j.processItem("pending"); j.processItem("closed"); j.processItem("rejected"); } void processItem(String s

Is it possible to compile class files with the Java 7 SDK which can run on Java 6 JVMs?

旧巷老猫 提交于 2019-11-30 07:58:13
问题 Since the public Java 6 SE JRE is getting closer to it's EOL (Nov '12), I'm considering porting my projects from Java 6 to Java 7. This would'nt be a big deal, if Apple would provide a Java 7 JRE for Mac OS X. But since Apple isn't willing to do so, I still have to support users which only have a Java 6 JRE. Is there a way to compile Java 6 compatible binaries (class files) with the Java 7 javac? Certainly I'm aware that I can't use the new Java 7 features when doing so. Thanks in anticiption

Why is Java 7 Files.walkFileTree throwing exception on encountering a tar file on remote drive

拈花ヽ惹草 提交于 2019-11-30 07:54:47
问题 Im using Files.WalkFileTree() to navigate folder and counting audio files, but there is a problem when it encounters a tar file, it seems to be treating it as an actual folder I was expecting it to just skip over it. I cannot see any options that let me control this behaviour Code: package com.jthink.songkong.fileloader; import com.jthink.songkong.cmdline.SongKong; import com.jthink.songkong.ui.MainWindow; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java

Why is the switch statement faster than if else for String in Java 7?

…衆ロ難τιáo~ 提交于 2019-11-30 07:54:46
问题 In Java 7 a string object can be in the expression of a switch statement. Can someone explain the below statement from official documentation? The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements. 回答1: Java Code Having two versions of a class, e.g. With if-then-else : public class IfThenElseClass { public static void main(String[] args) { String str = "C"; if ("A".equals(str)) { } else if ("B"

Why isn't getSelectedItem() on JComboBox generic?

蓝咒 提交于 2019-11-30 07:49:10
JCombobox in Java 7 has been updated to use generics - I always thought it was a bit of an oversight that it didn't already so I was pleased to see this change. However, when attempting to use JCombobox in this way, I realised that the methods I expected to use these generic types still just return Object. Why on earth is this? It seems like a silly design decision to me. I realise the underlying ListModel has a generic getElementAt() method so I'll use that instead - but it's a bit of a roundabout way of doing something that appears like it could have been changed on JComboBox itself. jarnbjo