java-7

Null-safe Method invocation Java7

自作多情 提交于 2019-12-18 13:12:45
问题 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? 回答1: Null-safe method invocation was proposed for Java 7 as a part of Project Coin,

Ambiguous method in Java 8, why? [duplicate]

雨燕双飞 提交于 2019-12-18 12:54:18
问题 This question already has answers here : Java type inference: reference is ambiguous in Java 8, but not Java 7 (2 answers) Closed 4 years ago . 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

Regular Expression named capturing groups support in Java 7

谁说胖子不能爱 提交于 2019-12-18 12:49:45
问题 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? 回答1: 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

Why isn't getSelectedItem() on JComboBox generic?

五迷三道 提交于 2019-12-18 12:45:22
问题 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

Why isn't getSelectedItem() on JComboBox generic?

余生长醉 提交于 2019-12-18 12:44:59
问题 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

Type-parameterized field of a generic class becomes invisible after upgrading to Java 7

旧时模样 提交于 2019-12-18 12:03:41
问题 Now Eclipse Indigo SR1 with builtin Java 7 support is finally out since a week or two, I'm migrating my playground projects from Helios SR2 + JDK 1.6_23 to Indigo SR1 + JDK 1.7.0. After a full rebuild of all projects, only one class has failed to compile. It's the following class which compiles and runs perfectly fine on Java 1.6 (and 1.5): public abstract class Area<A extends Area<?>> implements Comparable<Area<?>> { private String name; private Area<?> parent; private Set<A> areas;

ClassValue in Java 7

房东的猫 提交于 2019-12-18 11:47:19
问题 While browsing the Java 7 API documentation I stumbled upon the new class java.lang.ClassValue with the following rather minimal documentation: Lazily associate a computed value with (potentially) every type. For example, if a dynamic language needs to construct a message dispatch table for each class encountered at a message send call site, it can use a ClassValue to cache information needed to perform the message send quickly, for each class encountered. Can anyone give a better explanation

SSL Client Authentication with smart card works in Java 6 but fails in Java 7

倖福魔咒の 提交于 2019-12-18 10:46:19
问题 the following code creates a client authenticated SSL context using PKCS#11 device (smart card). It all works great with Java 6: // Configure the SunPkcs11 provider String pkcs11config; pkcs11config = "name = Cryptoki"; pkcs11config += "\nlibrary = /SCDriver/libbit4ipki.dylib"; InputStream confStream = new ByteArrayInputStream(pkcs11config.getBytes()); SunPKCS11 sunpkcs11 = new SunPKCS11(confStream); Security.addProvider(sunpkcs11); // Specify keystore builder parameters for PKCS#11 keystores

Maven doesn't use Java 7

巧了我就是萌 提交于 2019-12-18 10:14:58
问题 I want to package a maven-(multi)module, the parent POM includes: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> I'm using Java 1.7 and the properties are specified as follows: <properties> <project.build.sourceEncoding>UTF-8</project

TLS 1.2 was supported in Java 8 but not in Java 7

落花浮王杯 提交于 2019-12-18 08:59:02
问题 When I tried to connect a URL (one of vendors URL which supports TLS 1.2 and worked fine previously with Java 7) by using Java 7, I found bellow Exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1943) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1059) at