Hervian / lambda-factory

A fast alternative to Java Reflection API's method invocation
Apache License 2.0
119 stars 33 forks source link

What about generics, and why the snake case naming? #14

Open Mechite opened 1 year ago

Mechite commented 1 year ago

Instead of performing an unchecked cast on Lambda#invoke_for_Object, why don't we do it with generics instead and perform the unchecked class in the library?

<T> T invoke_for_Generic() {
    return (T) invoke_for_Generic(); // unchecked cast
}

e.g.

// (...)
Lambda lambda = LambdaFactory.create(method);
// String string = lambda.invoke_for_Generic<String>();
String string = lambda.invoke_for_Generic(); // inferred
// (...)

Also, though I know this is not going to be changed as this library is likely already in use by a lot of people (LambdaMetaFactory has horrible documentation, and I naturally stumbled upon it) - why snake_case? invokeForObject, invokeForBoolean is much more idiomatic.

Nobody is going to assume that invokeForBoolean returns a boxed boolean, they will check and they will have read the documentation, and they will know it isn't boxed.