Package org.web3j.abi
Class TypeReference<T extends Type>
java.lang.Object
org.web3j.abi.TypeReference<T>
- All Implemented Interfaces:
Comparable<TypeReference<T>>
- Direct Known Subclasses:
TypeReference.StaticArrayTypeReference
public abstract class TypeReference<T extends Type>
extends Object
implements Comparable<TypeReference<T>>
Type wrapper to get around limitations of Java's type erasure. This is so that we can pass around
Typed
Array types.
See this blog post for further details.
It may make sense to switch to using Java's reflection Type to avoid working around this fundamental generics limitation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTypeReference.StaticArrayTypeReference<T extends Type> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(TypeReference<T> o) static <T extends Type>
TypeReference<T>static <T extends Type>
TypeReference<T>getAtomicTypeClass(String solidityType, boolean primitives) This is a helper method that only works for atomic types (uint, bytes, etc).Workaround to ensure type does not come back as T due to erasure, this enables you to create a TypeReference viaClass<T>.getType()booleanstatic TypeReferencemakeTypeReference(String solidityType) static TypeReferencemakeTypeReference(String solidityType, boolean indexed, boolean primitives)
-
Field Details
-
ARRAY_SUFFIX
-
-
Constructor Details
-
TypeReference
protected TypeReference() -
TypeReference
protected TypeReference(boolean indexed)
-
-
Method Details
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends Type>
-
getType
-
isIndexed
public boolean isIndexed() -
getClassType
Workaround to ensure type does not come back as T due to erasure, this enables you to create a TypeReference viaClass<T>.- Returns:
- the parameterized Class type if applicable, otherwise a regular class
- Throws:
ClassNotFoundException- if the class type cannot be determined
-
create
-
create
-
getAtomicTypeClass
protected static Class<? extends Type> getAtomicTypeClass(String solidityType, boolean primitives) throws ClassNotFoundException This is a helper method that only works for atomic types (uint, bytes, etc). Array types must be wrapped by aParameterizedType.- Parameters:
solidityType- the solidity as a string eg Address Intprimitives- is it a primitive type- Returns:
- returns
- Throws:
ClassNotFoundException- when the class cannot be found.
-
makeTypeReference
- Throws:
ClassNotFoundException
-
makeTypeReference
public static TypeReference makeTypeReference(String solidityType, boolean indexed, boolean primitives) throws ClassNotFoundException - Throws:
ClassNotFoundException
-