Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
Alias types behave like different classes when you write code
Alias types behave like base type in runtime
Alias types still can have additional code (may be working like extensions do now)
Any conversions between aliases of the same class should be explicit A a = new B() -> error and for example A a = new B().convertTo(A.class)
Here is the most simple and obvious use case:
method(String a, String b, String c, String d, String e, .....)
It's very easy to make a mistake in parameters order - and all will go totally wrong.
method(A a,B b, C c, D d, E e, .....)
A bit more type safety - and you have show ball chance to break this call.
Also code completion will be far more precise.
Of cause that could be solved by wrappers:
class A {
String aValue;
}
But that decreases performance. And this is just first step of the dance. Others are to teach all (de)serializers to handle them (json, orm, mapstruct to DTOs like protobuf generated classes, ...) - that seems to be quite painful, or can reduce performance even more when using class Wrapper as base class for all wrappers and using reflection to make things working.
Concept - class aliases.
A a = new B() -> error
and for exampleA a = new B().convertTo(A.class)
Here is the most simple and obvious use case:
method(String a, String b, String c, String d, String e, .....)
It's very easy to make a mistake in parameters order - and all will go totally wrong.method(A a,B b, C c, D d, E e, .....)
A bit more type safety - and you have show ball chance to break this call. Also code completion will be far more precise.Of cause that could be solved by wrappers:
But that decreases performance. And this is just first step of the dance. Others are to teach all (de)serializers to handle them (json, orm, mapstruct to DTOs like protobuf generated classes, ...) - that seems to be quite painful, or can reduce performance even more when using class Wrapper as base class for all wrappers and using reflection to make things working.
Class aliases seem to be a perfect solution:
or