To answer your questions:
As AlbertoSinigaglia and Pshemo both said, the constructs you asked about:
in.<User>readParcelable(User.class.getClassLoader()
and
in.<AuthCredential>readParcelable(AuthCredential.class.getClassLoader()
are both examples of a "function with a template".
You can read more details in Oracle's Java tutorials:
Quoting from the "Type Inference" tutorial:
Type inference is a Java compiler's ability to look at each method invocation and corresponding declaration to determine the type
argument (or arguments) that make the invocation applicable.
Consider the following example, BoxDemo, which requires the Box class:
public class BoxDemo {
public static <U> void addBox(U u,
java.util.List<Box<U>> boxes) {
Box<U> box = new Box<>();
box.set(u);
boxes.add(box);
}
public static <U> void outputBoxes(java.util.List<Box<U>> boxes) {
int counter = 0;
for (Box<U> box: boxes) {
U boxContents = box.get();
System.out.println("Box #" + counter + " contains [" +
boxContents.toString() + "]");
counter++;
}
}
public static void main(String[] args) {
java.util.ArrayList<Box<Integer>> listOfIntegerBoxes =
new java.util.ArrayList<>();
BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
BoxDemo.addBox(Integer.valueOf(20), listOfIntegerBoxes);
BoxDemo.addBox(Integer.valueOf(30), listOfIntegerBoxes);
BoxDemo.outputBoxes(listOfIntegerBoxes);
}
}
The generic method addBox defines one type parameter named U.
Generally, a Java compiler can infer the type parameters of a generic
method call. Consequently, in most cases, you do not have to specify
them. For example, to invoke the generic method addBox, you can
specify the type parameter with a type witness as follows:
BoxDemo.<Integer>addBox(Integer.valueOf(10), listOfIntegerBoxes);
Alternatively, if you omit the type witness,a Java compiler
automatically infers (from the method's arguments) that the type
parameter is Integer:
BoxDemo.addBox(Integer.valueOf(20), listOfIntegerBoxes);
- Finally, regarding "It looks almost like a cast for the function result.":
Java - Generics vs Casting Objects
The point of generics is NOT to allow a class to use different types
at the same time.
Generics allow you to define/restrict the type used by an instance of
an object.
The idea behind generics is to eliminate the need to cast.