Interface Generic

  • All Superinterfaces:
    HasCopy<Generic>

    public interface Generic
    extends HasCopy<Generic>
    A model that represents the generic part of a type declaration in code. A type can have multiple generics.
    Since:
    2.0
    Author:
    Emil Forslund
    • Method Detail

      • setLowerBound

        Generic setLowerBound​(String lowerBound)
        Sets the lower bound of this generic.

        In the following example, T is the lower bound:

             T extends List<String>
         

        If the lower bound is anonymous, the special type DefaultType.WILDCARD can be used.

        Parameters:
        lowerBound - the new lower bound
        Returns:
        a reference to this model
      • getLowerBound

        Optional<String> getLowerBound()
        Returns the lower bound of this generic if it exists.

        In the following example, T is the lower bound:

             T extends List<String>
         

        If the lower bound is anonymous, the special type DefaultType.WILDCARD can be used.

        Returns:
        the lower bound if such exists
      • add

        default Generic add​(Type upperBound)
        Adds an upper bound to this generic.

        In the following example, List<String> and Serializable are upper bounds:

             T extends List<String>&Serializable
         
        Parameters:
        upperBound - the new upper bound
        Returns:
        a reference to this model
      • getUpperBounds

        List<Type> getUpperBounds()
        Returns a modifiable list of all upper bounds to this generic.

        In the following example, List<String> and Serializable are upper bounds:

             T extends List<String>&Serializable
         
        Returns:
        the list of upper bounds
      • setBoundType

        Generic setBoundType​(Generic.BoundType type)
        Sets the bound type of this generic. If the generic is bound using the extends keyword it means that the lower bound is a descendant of the upper bound. If the super keyword is used it means that the lower bound is an ancestor of the upper bound. Both bound types also accept identical types.

        Valid input:

        Parameters:
        type - the new bound type
        Returns:
        a reference to this model
      • getBoundType

        Generic.BoundType getBoundType()
        Returns the current bound type of this generic. Note that the bound type is irrelevant when there are no upper bounds!
        Returns:
        the bound type
      • asType

        Type asType()
        Parses a Type from the lower bound of this generic. This can be used to reference the generic variable from other contexts.
        Returns:
        a Type representing this generic variable
      • of

        static Generic of()
        Creates a new instance implementing this interface by using the default implementation.
        Returns:
        the new instance
      • of

        static Generic of​(String lowerBound)
        Creates a new instance implementing this interface by using the default implementation.
        Parameters:
        lowerBound - the lower bound, example: "T"
        Returns:
        the new instance
      • of

        static Generic of​(Type upperBound)
        Creates a new instance implementing this interface by using the default implementation.
        Parameters:
        upperBound - the upper bound, example: "String"
        Returns:
        the new instance