for-each
Cannot delete elements can only be traversed forward, cannot traverse two sets at the same time
enum (enumeration type)
There are as many instance objects as there are values, and you cannot directly enumerate objects with new
You can also add properties, constructors, and methods.
The constructor can be default, private internal call
Non-directional parameter
Add 3 dots after the type... essentially an array
A method can only have one non-directed parameter, which must be at the end of the parameter list
Import static
Automatic boxing and unboxing
Basic type boolean/byte/char/int/short/long/float/double
对象boole/Byte/Character/Integer/Short/Long/Float/Double
==, the basic type is whether the content is the same, when the object is to judge whether the pointer is the same
Multiple exceptions in parallel | There can be no inheritance relationship between pipe symbol exceptions
Integer type binary direct assignment
Numerical literals can use underscores between numbers
interface
The default method of the interface default is the flag of the non-permission default method and the implementation can be inherited by subclasses
The static method static of the interface cannot be passed to subclass objects and cannot be called
The private method private of the interface cannot be passed to the subclass
None of the interfaces can be instantiated (new)
try-with-resource
Principle: The resource object must implement the AutoCloseable interface, that is, implement the close() method. Automatically close, can directly use external resource
var type
Local variable inference (personally feels similar to python) is essentially a strong type, the compiler automatically infers the type, and the type cannot be changed after inference.
Cannot be used in method (formal) parameters and return types
Branch merge switch -> Direct connection judgment conditions and actions
Generic<>
Benefits can be referenced by different types of objects
Essential parameterized type, avoid type conversion, code can be reused
Generic classes use <T> after the class name to represent the introduced type
When a generic interface implements an interface, specify the type. T in <T> can also be generic again
Generic method <T> after the modifier, before the return type
Upper bound qualifier extends
Can only get, not set, because the compiler does not know what type is put in, it can only guarantee what type is out, it can definitely be transformed to S (can be received with S)
Lower bound qualifier super
You can only set, not get. The compiler guarantees that the s class or the super class of s is put in, but it cannot guarantee what type it is. It can only be received by object
There is no relationship between pari<T> and pari<S> generics (inheritance, etc.), regardless of the relationship between T and S
pecs principle
<?> Unqualified wildcard, can represent any type