# 记录

## Java Streams vs. Reactive Streams

### Java: imperative + object-oriented

Michael Feather:

​ “In OPP we encapsulate the moving parts; in FP we eliminate the moving parts.”

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

//double of even numbers
List<Integer> doubled = new ArrayList<>();

for (int i = 0; i < numbers.size(); i++) {
if (numbers.get(i) % 2 == 0) {
}
}
System.out.println(doubled);

System.out.println(
numbers.stream()
.filter( e -> e % 2 == 0)
.map( e -> e * 2)
.collect(toList()));


## Java虚方法调用

### Java virtual method invocation  2020年1月24日

​ When multiple overloaded methods are present, Java looks for the closest match first. It tries to find the following:

• Exact match by type
• Matching a superclass type
• Converting to larger primitive type
• Converting to an autoboxed type
• Varargs

For overriding, the overridden method has a few rules:

• The access modifier must be the same or more accessible.
• The return type must be the same or a more restrictive type, also known as covariant return types.
• If any checked exceptions are thrown, only the same exceptions or subclasses of those exceptions are allowed to be thrown.

The method must not be static. (If they are, the method is hidden and not overridden.)

#### 关于 instanceof 操作符，null 的情况，null 不是 Object.

instanceof 不能比较没有任何继承关系的类。 而接口可以，因为接口可以被实现。