Java


API:

Pattern matching (switch-case)

switch(exp) {
  case One -> 1;
  case Two -> 2;
  default -> 3;
}

See:

Method references

https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

Example in above link:

Arrays.sort(rosterAsArray,
    (a, b) -> Person.compareByAge(a, b)
);

can be achieved with

Arrays.sort(rosterAsArray, Person::compareByAge);

ie, kind of like the usual way of using functions in Haskell.

Interface

Functional interface

The value would take the role of the function that was left abstract.

Can think of functions more like values ??

See:

$ in identifiers

$ is allowed in identifiers, but it is meant to be used selectively by convention.

TL;DR: Better not use it.

From oracle website:

The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

See:

Generics

Function interfaces

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/function/Function.html

Interface Type
Function<A ,B> A -> B
BiFunction<A, B, C> (A, B) -> C
BinaryOperator<T> (T, T) -> T
UnaryOperator<T> T -> T

Composition

These two are apparently the same, but with argument order reversed.

I guess g.compose(f) is there to be more in line of what we mean when we say g ∘ f in theory. ie, first do f and then do g.

While writing in Java, often the andThen version is more convenient.

Record class

See:

Sealed classes and interfaces

Enforces a form of subtyping ??

See:

Wrapper classes for primitive types

There are 8 primitive data types in Java. Some of them:

Primitive Wrapper
float Float
double Double
char Character
boolean Boolean
string String

https://en.wikipedia.org/wiki/Primitive_wrapper_class_in_Java

'double cannot be converted to float'

Double dD = 3.14;
dD.floatValue(); // is type Float

double dd = 3.14;:w
(float) dd; // is type Float ??

https://stackoverflow.com/questions/32837783/convert-double-to-float-in-java

A sub-set of built-in exceptions

https://programming.guide/java/list-of-java-exceptions.html

Find size of an object

Packaging

Remarks

Doubts:

Misc