Package randoop.types

Class VoidType

  • All Implemented Interfaces:
    Comparable<Type>

    public class VoidType
    extends Type
    Represents void. Technically, void is used to indicate that a method has no return values, and is not a type. However, we need to pretend that it is to be able to represent typed operations.

    The decision to have void be a separate "type" is counter to the fact that the reflection method Class.isPrimitive() returns true for void.

    • Field Detail

      • value

        private static final VoidType value
    • Constructor Detail

      • VoidType

        private VoidType()
    • Method Detail

      • getVoidType

        public static VoidType getVoidType()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getRuntimeClass

        public Class<?> getRuntimeClass()
        Description copied from class: Type
        Returns the runtime Class object for this type. For use when reflection is needed.

        Note that type variables and the null reference type do not have a runtime class, and this method will return null in those cases.

        This method should not be confused with the inherited Object.getClass() method, which returns the Class<?> for the Type object, and not of the represented type. For instance, if a Type object t represented the Java type int, then t.getRuntimeClass() would return int.class while t.getClass() would return Type.class.

        Specified by:
        getRuntimeClass in class Type
        Returns:
        the Class that is the runtime representation of the type, or null if this type is a type variable or null reference type
      • getFqName

        public String getFqName()
        Description copied from class: Type
        Returns the fully-qualified name of this type, including type arguments if this is a parameterized type. For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getFqName in class Type
        Returns:
        the fully-qualified type name for this type
      • getBinaryName

        public String getBinaryName()
        Description copied from class: Type
        Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name). For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getBinaryName in class Type
        Returns:
        the binary name for this type
      • getSimpleName

        public String getSimpleName()
        Description copied from class: Type
        Returns the name of this type without type arguments or package qualifiers. For java.util.List<T>, returns "List".
        Specified by:
        getSimpleName in class Type
        Returns:
        the name of this type without type arguments
      • isVoid

        public boolean isVoid()
        Description copied from class: Type
        Indicate whether this type is void.
        Overrides:
        isVoid in class Type
        Returns:
        true if this type is void, false otherwise
      • isSubtypeOf

        public boolean isSubtypeOf​(Type otherType)
        Test whether this type is a subtype of the given type according to transitive closure of definition of the direct supertype relation in section 4.10 of JLS for Java SE 8.

        Returns false, since void is not a subtype of any type

        Overrides:
        isSubtypeOf in class Type
        Parameters:
        otherType - the possible supertype
        Returns:
        true if this type is a subtype of the given type, false otherwise
      • isAssignableFrom

        public boolean isAssignableFrom​(Type sourceType)
        Indicates whether there is an assignment conversion from a source Type to this type. (In other words, a value of the source type can be assigned to an l-value of this type.) Returns true if this is a legal assignment conversion: Variablethis = Expressionsourcetype.

        Based on the definition of assignment context in section 5.2 of the Java Language Specification, a value of one type is assignable to a variable of another type if the first type can be converted to the second by

        • an identity conversion (section 5.1.1),
        • a widening primitive conversion (section 5.1.2),
        • a widening reference conversion (section 5.1.5),
        • a boxing conversion (5.1.7), or
        • an unboxing conversion (section 5.1.8) possibly followed by a widening conversion.
        And, if after all those conversions, the type is a raw type, an unchecked conversion may occur.

        Return false because cannot assign to void.

        Overrides:
        isAssignableFrom in class Type
        Parameters:
        sourceType - the type to test for assignability
        Returns:
        true if this type can be assigned from the source type, and false otherwise