When working with Variants you can use the default constructor which is taking your object, but that will not work if you use Maps/Collections because the actual type(s) used inside of those objects are not known on runtime (due to Java type erasure).
In this case you can use this builder providing the Class type you want to have inside of your Variant (e.g. Map.class) and the generic class types used inside of the Map.
Example:
VariantBuilder.of(Map.class).withGenericTypes(String.class, Integer.class).create(myMap);
- Since:
- 5.1.1 - 2024-08-16
- Author:
- hypfvieh
-
Method Summary
Modifier and TypeMethodDescription<X> Variant<X> create(X _data) Create the Variant instance using the provided data object.static VariantBuilderCreate a new instance using the given class as starting point.withGenericTypes(Class<?>... _clz) Add one or more generic types.
-
Method Details
-
of
Create a new instance using the given class as starting point.If you want to create Variant containing a Map or List, this would be Map/List.class.
- Parameters:
_clz- class to use, never null- Returns:
- new instance
-
withGenericTypes
Add one or more generic types.Use this if you want to create a Variant containing a Map, Collection. You have to provide the data types used inside of your Map/Collection to this method. E.g. you have Map>Integer,String< than you have to provide Integer.class and String.class to this method.
- Parameters:
_clz- generic classes to add- Returns:
- this
-
create
Create the Variant instance using the provided data object.- Type Parameters:
X- Type inside of the Variant- Parameters:
_data- data to store in Variant- Returns:
- Variant
- Throws:
IllegalArgumentException- when provided data object is not compatible with class given in constuctorNullPointerException- when null is given
-