eclipseday2011-110511032907-phpapp02
TRANSCRIPT
-
7/30/2019 eclipseday2011-110511032907-phpapp02
1/19
IBM 2011. Licensed under EPL v1.0
SE 7 : What's New!
Ayushman Jain
JDT/Core committerIBM
-
7/30/2019 eclipseday2011-110511032907-phpapp02
2/19
IBM 2011. Licensed under EPL v1.0
New features at a glance
Project Coin small enhancement and new languagefeatures.
Support for dynamic languages.
Unicode 6.0 new rupee symbol, brahmi script,emoticons.
New I/O and concurrent APIs.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
3/19
IBM 2011. Licensed under EPL v1.0
Project coin features
Binary literals and underscores in literals.
Strings in switch.
@SafeVarargs - Varargs warnings.
Diamond - improved type inference for generic instance
creation.
Multi-catch and more precise rethrow.
try-with-resources (formerly known as AutomaticResource Management or ARM).
-
7/30/2019 eclipseday2011-110511032907-phpapp02
4/19
IBM 2011. Licensed under EPL v1.0
Strings in switch When do you use a switch statement?
Valid case labels upto javaSE 6 can be Int constants
Enum constants String can also be constants!
-
7/30/2019 eclipseday2011-110511032907-phpapp02
5/19
IBM 2011. Licensed under EPL v1.0
Safe Varargs
Variable arity method - public static Listjava.util.Arrays.asList(T... a)
If T is the parameter type with variable arity and is alsonon-reifiable, a new warning on declaration of variablearity methods with parameter of type T.
A new annotation @SafeVarargs to suppress thewarning at both declaration site and call site.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
6/19
IBM 2011. Licensed under EPL v1.0
Reifiable types A type whose type information is fully available at
runtime, that is, a type that does not lose informationin the course of type erasure.
Any type with type parameters is available to the JVM asthe raw type because of type erasure.
So List and List are both seen as Listby the JVM.
Hence parameterized types are non-reifiable.
On the other hand, types such as String are reifiable.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
7/19
IBM 2011. Licensed under EPL v1.0
Safe Varargs A variable arity parameter of a generic type can cause
heap pollution.
public static List java.util.Arrays.asList(T... a)
Heap pollution - A situation where a variable of a
parameterized type refers to an object that is not ofthat parameterized type.
Usually, the method body is well behaved and onlyiterates over the elements.
Hence, unchecked warning is mostly a distraction.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
8/19
IBM 2011. Licensed under EPL v1.0
@SafeVarargs
Annotation legal on static or final variable arity methodsor constructors.
Not legal on
Fixed arity methods or constructors. Variable arity methods or constructors that are
neither final nor static.
Some java APIs already retrofitted with the annotation inJDK 7.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
9/19
IBM 2011. Licensed under EPL v1.0
Binary Integer Literals and
Underscores in numeric literals
Binary integer literals structured just like hex intergerliterals. Differences:
Binary digits used instead of hex digits
0b now used instead of 0x In numeric literals, underscores now permitted as separators
between digits.
Applies to literals in any base: binary, octal, hexadecimal, ordecimal
Applies to both integer literals and floating point literals
-
7/30/2019 eclipseday2011-110511032907-phpapp02
10/19
IBM 2011. Licensed under EPL v1.0
Multi-catch and more precise
rethrow
Different catch blocks performing the same action on thecaught exception.
They can now be combined into one single catch block
using Disjunctive types.
Disjunctive type = ExceptionA | ExceptionB | ....
Disjunctive types implicitly final.
Also, now only the actually thrown exception is nowrethrown and not its parent type.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
11/19
IBM 2011. Licensed under EPL v1.0
Try With Resources Language & Library changes to
Ease management of objects that require explicitfreeing/disposal/destruction.
Prevent resource leaks (handles, streams ...)
A la Destructors in C++ (and others) Library changes:
A new interface java.lang.AutoCloseable.
Libraries retrofitted to implement the new interface
Facilities to manage suppressed exceptions onjava.lang.Throwable
-
7/30/2019 eclipseday2011-110511032907-phpapp02
12/19
IBM 2011. Licensed under EPL v1.0
What is a Resource Basically a final variable local to the try block.
Must be of type AutoCloseable. Must be initialized in the resource section.
Language guarantees that every successfullyinitialized non-null resource will be closed.
Will be closed regardless of normal or abrupt
completion.
In LIFC order: Last initialized first closed.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
13/19
IBM 2011. Licensed under EPL v1.0
Suppressed exceptions
Primary exception will be the exception seen by a usersupplied catch block.
Exception from close methods are added to the
suppressed list of primary exception (unless it is theprimary exception.)
An interested party can query and process suppressedexceptions. New APIs in class Throwable:
public final void addSuppressed(Throwable);
public final Throwable [] getSuppressed();
-
7/30/2019 eclipseday2011-110511032907-phpapp02
14/19
IBM 2011. Licensed under EPL v1.0
Diamond Improved type inference for generic instance
creation. Before,
List list = new ArrayList();
Now,
List list = new ArrayList();
Why not List list = new ArrayList() ?
-
7/30/2019 eclipseday2011-110511032907-phpapp02
15/19
IBM 2011. Licensed under EPL v1.0
Support for dynamic languages A growing interest in running programs written in
dynamic languages on JVM.
Particularly scripting languages-JRuby,Jpython,Groovy.
Motivation make implementation in such languages
efficient and fast. Current Problem - JVM instruction to invoke a method takes
method descriptor as the argument
Method descriptor is the method name, argumenttypes and the return type.
Solution new invokeDynamicinstruction and dynamiclinking through method handles.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
16/19
IBM 2011. Licensed under EPL v1.0
JVM bytecode instructions invokevirtual - Invokes a method on a class. This is the
typical type of method invocation.
invokeinterface - Invokes a method on an interface.
invokestatic - Invokes a static method on a class. This isthe only kind of invocation that lacks a receiverargument.
invokespecial - Invokes a method without reference tothe type of the receiver.
invokedynamic- enables an implementer of a dynamiclanguage to translate a method invocation intobytecode without having to specify a target type that
contains the method.
-
7/30/2019 eclipseday2011-110511032907-phpapp02
17/19
IBM 2011. Licensed under EPL v1.0
Method handles Consider hypothetical dynamic language code
function max (x,y) {if x.lessThan(y) then y else x }
To compile this for JVM
MyObject function max (MyObject x,MyObject y) {
if x.lessThan(y) then y else x }
Or use reflection. With Java7, use method handles!
-
7/30/2019 eclipseday2011-110511032907-phpapp02
18/19
IBM 2011. Licensed under EPL v1.0
Use Eclipse for java 7
No builds available as of today.
Setup Eclipse to work for java 7 as described
in http://wiki.eclipse.org/JDT_Core/Java7
-
7/30/2019 eclipseday2011-110511032907-phpapp02
19/19
IBM 2011. Licensed under EPL v1.0
Thank You!