The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Name

SPVM::Document::Language::Types - Types in the SPVM Language

Description

This document describes types in the SPVM language.

Data

This section describes data.

A data is called value.

Number

The value of numeric types is called number.

Normally, numbers are created by numeric literals.

  # byte - 8bit signed integer
  my $number = (byte)1;
  
  # short - 16bit signed integer
  my $number = (short)1;
  
  # int - 32bit signed integer
  my $number = 1;
  
  # long - 64bit signed integer
  my $number = 1L;
  
  # float - 32bit floating point
  my $number = 1.5f;
  
  # double - 64bit floating point
  my $number = 1.0;

A character created by the character literal is a number of the byte type.

  # A number of the byte type created by a character literal
  my $char = 'a';

See the following section operations for numbers.

Internal Representation of Negative Integers

Negative integers are represented by two's complement.

String

The value of the string type is called string.

A string consists of characters of the byte type.

A string has its length.

A string is an object.

Normally, a string is created by a string literal or the new_string_len operator.

  # A string created by a string literal
  my $string = "Hello";
  my $char = $string->[0];
  
  # A mutable string created by the new_string_len operator
  my $string = new_string_len 3;
  $string->[0] = 'a';

See the following sections about operations for strings.

Sting Native Level Representation

At the native level, the character just after the last character of the string is set to \0, so the characters in the string can be used as a C language string.

  # The characters in the string can be used as a C language string
  void* obj_string = stack[0].oval;
  const char* chars = env->get_chars(env, stack, obj_string);
  if (strcmp(chars, "Hello") == 0) {
    
  }

Array

The value of an array type is called array.

An array consists of a set of numbers, a set of objects, or a set of multi-numeric numbers.

An array has its length.

The elements of an array are arranged by index and the index starts from 0.

An array is an object.

Normally, an array is created by the new Operator and an array initialization.

  # An array created by the new operator
  my $numbers = new int[3];
  $numbergers->[0] = 1;
  
  my $strings = new string[3];
  
  my $objects = new Point[3];
  
  my $mulnum_numbers = new Complex_2d[3];
  
  # An array created by an array initialization
  my $numbers = [1, 2, 3];

All elements of an array can be got by the for statement.

  # for statement
  for (my $i = 0; $i < @$numbers; $i++) {
    my $number = $numbers->[$i];
  }
  
  # for-each statement
  for my $number (@$numbers) {
    
  }

See the following sections about operations for arrays.

Object

The value of an object type is called object.

A string is an object.

An array is an object.

An objcet of the class type has its fields. A field is a number or an object.

Normally, an object is created by the new operator.

  # An object created by the new operator
  my $point = new Point;

When an object is created, memory for the object is allocated in heap memory.

Created objects are destroyed by garbage collection.

See the following sections about operations for objects.

Object Native Level Representation

At native level, an object is a memory address.

  void* obj_point = stack[0].oval;

Undefined Value

The value of the undef type is called undefined value.

An undefined value means the value is undefined.

An undefined value is created by the undef operator.

  undef

An undefined value is able to be assigned to an object type.

  my $point : Point = undef;

Examples:

  # Examples of undefined values
  my $string : string = undef;
  
  if (undef) {
    
  }
  
  my $message = "Hello";
  if ($message == undef) {
    
  }

Undefined Value Native Level Representation

At native level, an undefined value is equal to 0, normally a null pointer NULL defined in stddef.h.

  NULL

Multi-Numeric Number

The value of a multi-numeric type is called multi-numeric number.

A multi-numeric number is a set of numbers of the same type.

  my $z : Complex_2d;
  $z->{re} = 1;
  $z->{im} = 2;

See the following sections about operations for multi-numeric numbers.

Reference

The value of a reference type is called reference.

A reference has a referencing value.

A referencing value must be a number or a multi-numeric number

The reference operator \ creates a reference.

  my $number : int;
  my $number_ref = \$number;

See the following sections about operations for multi-numeric numbers.

Reference Native Level Representation

At native level, a reference is a memory address.

  int32_t* num_ref = stack[0].iref;

Types

This section describes types.

Numeric Types

This section describes numeric types.

Integer Types

This section describes integer types.

An interger type is a numeric type.

byte Type

The byte type is the type for a signed 8-bit integer.

  byte

The byte type is an integer type.

short Type

The short type is the type for a signed 16-bit integer.

  short

The short type is an integer type.

int Type

The int type is the type for a signed 32-bit integer.

  int

The int type is an integer type.

long Type

The long type is the type for a signed 64-bit integer.

  long

The long type is an integer type.

Floating Point Types

This section describes floating point types.

A floating point type is a numeric type.

float Type

The float type is the type for 32bit floating point.

  float

The float type is a floating point type.

double Type

The double type is the type for 64bit floating point.

  double

The double type is a floating point type.

Numeric Types Order

numeric types have its order.

The order is byte, short, int, long, float, double from smallest to largest.

Object Types

This section lists object types.

string Type

The string type is the type for strings.

  string

The string type is an object type.

The string type can be qualified with the mutable type qualifier.

  mutable string

Class Types

A class type is the type for a class.

A class type is defined by class definition.

  class CLASS_TYPE {
  
  }

An object can be created from a class by a new operator.

Note that an interface type and a multi-numeric type is not a class type although these types are defined by class definition.

Numeric Object Types

A numeric object type is a class type that owns the corresponding field of a numeric type.

The List of Numeric Object Types:

Numeric Object Types Corresponding Numeric Types
Byte byte
Short short
Int int
Long long
Float float
Double double

Interface Types

An interface type is a type for an interface.

An interface type is defined by an interface definition.

  class INTERFACE_TYPE : interface_t {
    
  }

Any Object Type

Any object type object is the type to which any object type can be assigned.

  object

Examples:

  # Examples of any object type
  my $object: object = new Foo;

Basic Types

A basic type is a type whose type dimension is 0 and that can be an element of an array.

The List of Basic Types:

undef Type

The undef type is the type of an undefined value.

void Type

The void type is the type that represents a method defined by a method definition does not return a return value.

  void

Array Types

An array type is a type for an array. An array type consists of a basic type and a type dimension such as [], [][].

  BASIC_TYPE[]..

([].. means one more [])

Examples:

  # Numeric array
  int[]
  double[]
  
  # String array
  string []
  
  # Class array
  Point[]
  
  # Any object array
  object[]
  
  # 2 dimensional array
  int[][]
  
  # 3 dimensional array
  int[][][]

An array type is an object type.

Compilation Errors:

The dimesion is less than or equal to 255. Otherwise, a compilation error occurs.

Numeric Array Types

A numeric array type is an array type of a numeric type.

The List of Numeric Array Types:

  byte[]
  short[]
  int[]
  long[]
  float[]
  double[]

Object Array Types

An object array type is an array type of an object type.

Examples:

  Point[]
  Point[][]
  Stringable[]
  string[]
  object[]

String Array Type

The string array type is the array type the string type.

  string[]

Class Array Types

A class array type is an array type of a class type.

Examples:

  Int[]
  Point[]

Interface Array Types

An interface array type is an array type of an interface type.

Examples:

  Stringable[]
  Cloneable[]

Multi-Dimensional Array Types

A multi-dimensional array type is an array type of an array type.

Examples:

  int[][]
  Int[][]
  string[][][]
  object[][]

A multi-dimensional array is created by the syntax of creating a multi-dimensional array of the new operator.

Multi-Numeric Array Types

A multi-numeric array type is an array type of a multi-numeric type.

Examples:

  Complex_2d[]
  Complex_2f[]

Any Object Array Type

The any object array type object[] is the array type to which any object array type can be assigned.

  object[]

Multi-Numeric Types

A multi-numeric type is a type for a multi-numeric number.

A multi-numeric type is defined by a multi-numeric type definition.

  class MULNUM_TYPE : mulnum_t {
    
  }

Reference Types

A reference type is a type for a reference.

  TYPE*

A reference type consists of a type followed by *.

TYPE must be a numeric type or a multi-numeric type.

Numeric Reference Types

A numeric reference type is a reference type of a numeric type.

The List of Numeric Reference Types:

  byte*
  short*
  int*
  long*
  float*
  double*

Multi-Numeric Reference Types

A multi-numeric reference types is a reference type of a multi-numeric type.

  MULNUM_TYPE*

Examples:

  Complex_2d*
  Complex_2f*

Type Qualifiers

A type qualifier qualify a type.

  QUALIFIER TYPE

The QUALIFIER qualified the type TYPE.

mutable Type Qualifier

The mutable type qualifier qualifies the string type.

  mutable string;

The string of the string type with the mutable type qualifier is able to be set a character.

  my $string = (mutable string)copy "abc";
  $string->[0] = 'd';

Type Initial Value

The value of a type is initialized by its type initial value.

The List of Type Initial Values:

Types Type Initial Values
byte 0
short 0
int 0
long 0
float 0 (All bits are 0)
double 0 (All bits are 0)
Object Types undef
Multi-Numeric Types All fields are set to 0 (All bits are 0)

Type Width

The type width is the length of the runtime stack of the type.

If the type is a multi-numeric type, the type width is the length of the fields, owhterwise it is 1.

Assignment Requirement

The assignment requirement is the requirement whether one type is able to be assigned to another type.

What does it mean to assign one type to another type?

Typically, it is sufficient to consider a case where a value of a type TYPE_FROM is assigned to a variable of a type TYPE_TO.

  my $value : TYPE_FROM;
  my $var : TYPE_TO = $value;

Abstracting this, type-to-type assignment is defined.

  TYPE_TO = TYPE_FROM

Note that this is a concept, not an actual syntax.

Some assinments perform a data conversion.

In the following description, the word "Type" is omitted when it is obvious.

Assignment Requirement to Numeric

Assignment Requirement from Numeric to Numeric

To Larger:

Assignment Requirement
Satisfaction
ToFromData Conversion
YesbytebyteNo
YesshortshortNo
YesintintNo
YeslonglongNo
YesfloatfloatNo
YesdoubledoubleNo
YesshortbyteNumeric Widening Conversion
YesintbyteNumeric Widening Conversion
YeslongbyteNumeric Widening Conversion
YesfloatbyteNumeric Widening Conversion
YesdoublebyteNumeric Widening Conversion
YesintshortNumeric Widening Conversion
YeslongshortNumeric Widening Conversion
YesfloatshortNumeric Widening Conversion
YesdoubleshortNumeric Widening Conversion
YeslongintNumeric Widening Conversion
YesfloatintNumeric Widening Conversion
YesdoubleintNumeric Widening Conversion
YesfloatlongNumeric Widening Conversion
YesdoublelongNumeric Widening Conversion
YesdoublefloatNumeric Widening Conversion

To Smaller:

Assignment Requirement
Satisfaction
ToFromData Conversion
Conditional YesbyteshortNumeric Narrowing Conversion
Conditional YesbyteintNumeric Narrowing Conversion
Conditional YesbytelongNumeric Narrowing Conversion
NobytefloatNo
NobytedoubleNo
Conditional YesshortintNumeric Narrowing Conversion
Conditional YesshortlongNumeric Narrowing Conversion
NoshortfloatNo
NoshortdoubleNo
Conditional YesintlongNumeric Narrowing Conversion
NointfloatNo
NointdoubleNo
NolongfloatNo
NolongdoubleNo
NofloatdoubleNo

"Conditional Yes" means if the value of TYPE_FROM is represented by an interger literal and between the max and minimal value of the type of TYPE_TO.

Assignment Requirement from NumericObject to Numeric

Assignment Requirement
Satisfaction
ToFromData Conversion
YesbyteByteUnboxing Conversion
YesshortShortUnboxing Conversion
YesintIntUnboxing Conversion
YeslongLongUnboxing Conversion
YesfloatFloatUnboxing Conversion
YesdoubleDoubleUnboxing Conversion

Assignment Requirement from Any Object to Numeric

Assignment Requirement
Satisfaction
ToFromData Conversion
YesbyteAny Object objectUnboxing Conversion
YesshortAny Object objectUnboxing Conversion
YesintAny Object objectUnboxing Conversion
YeslongAny Object objectUnboxing Conversion
YesfloatAny Object objectUnboxing Conversion
YesdoubleAny Object objectUnboxing Conversion

Assignment Requirement from Other to Numeric

Assignment Requirement
Satisfaction
ToFromData Conversion
NoNumericXOtherNo

NumericX is a numeric type.

Assignment Requirement to Multi-Numeric

Assignment Requirement
Satisfaction
ToFromData Conversion
YesMulti-NumericXMulti-NumericXNo
NoMulti-NumericXOtherNo

Multi-NumericX is a multi-numeric type.

Assignment Requirement to Referenece

Assignment Requirement
Satisfaction
ToFromData Conversion
YesReferenceXReferenceXNo
NoReferenceXOtherNo

ReferenceX is a reference type.

Assignment Requirement to String

Assignment Requirement
Satisfaction
ToFromData Conversion
YesstringstringNo
Yesstringmutable stringNo
Yesmutable stringmutable stringNo
Nomutable stringstringNo
YesstringstringNo
YesstringNumericXNumeric-to-String Conversion
YesstringundefNo
NostringOtherNo

NumericX is a numeric type.

Assignment Requirement to NumericObject

Assignment Requirement
Satisfaction
ToFromData Conversion
YesNumericObjectXNumericObjectXNo
YesNumericObjectXNumericXBoxing Conversion
YesNumericObjectXundefNo
NoNumericObjectXOtherNo

NumericObjectX is a numeric object type.

NumericX is a numeric type.

Assignment Requirement to Class

Assignment Requirement
Satisfaction
ToFromData Conversion
YesClassXClassXNo
YesClassXundefNo
YesSuperClassXClassXNo
NoClassXOtherNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

Assignment Requirement to Interface

Assignment Requirement
Satisfaction
ToFromData Conversion
YesInterfaceXInterfaceXNo
YesInterfaceXInterfaceSatisfiedXNo
YesInterfaceXundefNo
NoInterfaceXOtherNo

InterfaceX is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Assignment Requirement to Any Object

Assignment Requirement
Satisfaction
ToFromData Conversion
YesAny Object objectObjectXNo
YesAny Object objectNumericXBoxing Conversion
YesAny Object objectundefNo
NoAny Object objectOtherNo

ObjectX is an object type.

NumericX is a numeric type.

Assignment Requirement to undef

Assignment Requirement
Satisfaction
ToFromData Conversion
NoundefXNo

X is a type.

Assignment Requirement to void

Assignment Requirement
Satisfaction
ToFromData Conversion
YesvoidvoidNo
NovoidXNo

X is a type.

Assignment Requirement to Numeric Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesNumericX[]NumericX[]No
YesNumericX[]undefNo
NoNumericX[]OtherNo

NumericX is a numeric type.

Assignment Requirement to Multi-Numeric Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesMulti-NumericX[]Multi-NumericX[]No
YesMulti-NumericX[]undefNo
NoMulti-NumericX[]OtherNo

Multi-NumericX is a multi-numeric type.

Assignment Requirement to String Array

Assignment Requirement
Satisfaction
ToFromData Conversion
Yesstring[]string[]No
Yesstring[]undefNo
Nostring[]OtherNo

Assignment Requirement to Class Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesClassX[]ClassX[]No
YesSuperClassX[]ClassX[]No
YesClassX[]undefNo
NoClassX[]OtherNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

Assignment Requirement to Interface Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesInterfaceX[]InterfaceX[]No
YesInterfaceX[]InterfaceSatisfiedX[]No
YesInterfaceX[]undefNo
NoInterfaceX[]OtherNo

InterfaceX is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Assignment Requirement to Any Object Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesAny Object Array object[]ObjectX[]..No
YesAny Object Array object[]undefNo
NoAny Object Array object[]OtherNo

ObjectX is an object type.

[].. is one or more [].

Assignment Requirement to Multi-Dimensional Array

Assignment Requirement
Satisfaction
ToFromData Conversion
YesX[]..DX[]..DNo
YesX[]..DundefNo
YesSuperClassX[]..DClassX[]..DNo
YesInterfaceX[]..DInterfaceSatisfiedX[]..DNo
NoX[]..DOtherNo

X is a type.

[].. is one or more [].

D means its type dimension that is greater than or eausl to 2.

X[]..D is a multi-dimensional array.

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Cast Requirement

The cast requirement is the requirement whether one type is able to be cast to another type.

What does it mean to cast one type to another type?

Typically, it is sufficient to consider a case where a value of a type TYPE_FROM is casted to TYPE_TO.

  my $value : TYPE_FROM;
  (TYPE_TO)$value;

Abstracting this, type-to-type cast is defined.

  (TYPE_TO)TYPE_FROM

Note that this is a concept, not an actual syntax.

Some type casts perform a data conversion.

Some type casts perform a data check.

In the following description, the word "Type" is omitted when it is obvious.

Cast Requirement to Numeric

Cast Requirement from Numeric to Numeric

To Larger:

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesbytebyteNoNo
YesshortshortNoNo
YesintintNoNo
YeslonglongNoNo
YesfloatfloatNoNo
YesdoubledoubleNoNo
YesshortbyteNumeric Widening ConversionNo
YesintbyteNumeric Widening ConversionNo
YeslongbyteNumeric Widening ConversionNo
YesfloatbyteNumeric Widening ConversionNo
YesdoublebyteNumeric Widening ConversionNo
YesintshortNumeric Widening ConversionNo
YeslongshortNumeric Widening ConversionNo
YesfloatshortNumeric Widening ConversionNo
YesdoubleshortNumeric Widening ConversionNo
YeslongintNumeric Widening ConversionNo
YesfloatintNumeric Widening ConversionNo
YesdoubleintNumeric Widening ConversionNo
YesfloatlongNumeric Widening ConversionNo
YesdoublelongNumeric Widening ConversionNo
YesdoublefloatNumeric Widening ConversionNo

To Smaller:

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesbyteshortNumeric Narrowing ConversionNo
YesbyteintNumeric Narrowing ConversionNo
YesbytelongNumeric Narrowing ConversionNo
YesbytefloatNumeric Narrowing ConversionNo
YesbytedoubleNumeric Narrowing ConversionNo
YesshortintNumeric Narrowing ConversionNo
YesshortlongNumeric Narrowing ConversionNo
YesshortfloatNumeric Narrowing ConversionNo
YesshortdoubleNumeric Narrowing ConversionNo
YesintlongNumeric Narrowing ConversionNo
YesintfloatNumeric Narrowing ConversionNo
YesintdoubleNumeric Narrowing ConversionNo
YeslongfloatNumeric Narrowing ConversionNo
YeslongdoubleNumeric Narrowing ConversionNo
YesfloatdoubleNumeric Narrowing ConversionNo

Cast Requirement from NumericObject to Numeric

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesbyteByteUnboxing ConversionNo
YesshortShortUnboxing ConversionNo
YesintIntUnboxing ConversionNo
YeslongLongUnboxing ConversionNo
YesfloatFloatUnboxing ConversionNo
YesdoubleDoubleUnboxing ConversionNo

Cast Requirement from Any Object to Numeric

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesNumericXAny Object objectUnboxing ConversionNo

NumericX is a numeric type.

Cast Requirement from Other to Numeric

Cast Requirement
Satisfaction
ToFromData ConversionData Check
NoNumericXOtherNoNo

NumericX is a numeric type.

Cast Requirement to Multi-Numeric

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesMulti-NumericXMulti-NumericXNoNo
NoMulti-NumericXOtherNoNo

Multi-NumericX is a multi-numeric type.

Cast Requirement to Referenece

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesReferenceXReferenceXNoNo
NoReferenceXOtherNoNo

ReferenceX is a reference type.

Cast Requirement to String

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesstringstringNoNo
Yesstringmutable stringNoNo
Yesmutable stringmutable stringNoNo
Yesmutable stringstringNois_read_only Operator
YesstringstringNoNo
YesstringNumericXNumeric-to-String ConversionNo
YesstringAny Object objectNoisa Operator
YesstringundefNoNo
NostringOtherNoNo

NumericX is a numeric type.

Cast Requirement to NumericObject

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesNumericObjectXNumericObjectXNoNo
YesNumericObjectXNumericXBoxing ConversionNo
YesNumericObjectXAny Object objectNoisa Operator
YesNumericObjectXundefNoNo
NoNumericObjectXOtherNoNo

NumericObjectX is a numeric object type.

NumericX is a numeric type.

Cast Requirement to Class

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesClassXClassXNoNo
YesSuperClassXClassXNoNo
YesClassXSuperClassXNoisa Operator
YesClassXInterfaceXNoisa Operator
YesClassXAny Object objectNoisa Operator
YesClassXundefNoNo
NoClassXOtherNoNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is a an interface type.

Cast Requirement to Interface

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesInterfaceXInterfaceXNoNo
YesInterfaceXInterfaceSatisfiedXNoNo
YesInterfaceXInterfaceYNoisa Operator
YesInterfaceXAny Object objectNoisa Operator
YesInterfaceXundefNoNo
NoInterfaceXOtherNoNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is a an interface type.

InterfaceY is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Cast Requirement to Any Object

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesAny Object objectObjectXNoNo
YesAny Object objectNumericXBoxing ConversionNo
YesAny Object objectundefNoNo
NoAny Object objectOtherNoNo

ObjectX is an object type.

NumericX is a numeric type.

Cast Requirement to Numeric Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
Yesbyte[]stringString-to-byte[] ConversionNo
YesNumericX[]NumericX[]NoNo
YesNumericX[]Any Object objectNoisa Operator
YesNumericX[]undefNoNo
NoNumericX[]OtherNoNo

NumericX is a numeric type.

Cast Requirement to Multi-Numeric Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesMulti-NumericX[]Multi-NumericX[]NoNo
YesMulti-NumericX[]Any Object objectNoisa Operator
YesMulti-NumericX[]undefNoNo
NoMulti-NumericX[]OtherNoNo

Multi-NumericX is a multi-numeric type.

Cast Requirement to String Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
Yesstring[]string[]NoNo
Yesstring[]Any Object objectNoisa Operator
Yesstring[]Any Object Array object[]Noisa Operator
Yesstring[]undefNoNo
Nostring[]OtherNoNo

Cast Requirement to Class Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesClassX[]ClassX[]NoNo
YesSuperClassX[]ClassX[]NoNo
YesClassX[]SuperClassX[]Noisa Operator
YesClassX[]Any Object objectNoisa Operator
YesClassX[]Any Object Array object[]Noisa Operator
YesClassX[]undefNoNo
NoClassX[]OtherNoNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

Cast Requirement to Interface Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesInterfaceX[]InterfaceX[]NoNo
YesInterfaceX[]InterfaceSatisfiedX[]NoNo
YesInterfaceX[]InterfaceY[]Noisa Operator
YesInterfaceX[]Any Object objectNoisa Operator
YesInterfaceX[]Any Object Array object[]Noisa Operator
YesInterfaceX[]undefNoNo
NoInterfaceX[]OtherNoNo

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is a an interface type.

InterfaceY is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Cast Requirement to Any Object Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesAny Object Array object[]ObjectX[]..NoNo
YesAny Object Array object[]undefNoNo
YesAny Object Array object[]Any Object objectNoisa Operator
NoAny Object Array object[]OtherNoNo

ObjectX is an object type.

[].. is one or more [].

Cast Requirement to Multi-Dimensional Array

Cast Requirement
Satisfaction
ToFromData ConversionData Check
YesX[]..DX[]..DNoNo
YesX[]..DAny Object objectNoisa Operator
YesX[]..DAny Object Array object[]Noisa Operator
YesX[]..DundefNoNo
YesSuperClassX[]..ClassX[]..DNoNo
YesClassX[]..SuperClassX[]..DNoisa Operator
YesInterfaceX[]..DInterfaceSatisfiedX[]..DNoNo
NoAny Object Array object[]OtherNoNo

X is a type.

[].. is one or more [].

D means its type dimension that is greater than or eausl to 2.

X[]..D is a multi-dimensional array.

ClassX is a class type.

SuperClassX is a super class of ClassX.

InterfaceX is a an interface type.

InterfaceSatisfiedX is a class type or an interface type that satisfied the interface requirement of InterfaceX.

Interface Requirement

The interface requirement is the requirement whether an object type is able to be assigned to an interface type.

  INTERFACE_TYPE_TO = OBJECT_TYPE_FROM

This is the same concept as type-to-type assignment explained in Assignment Requirement.

INTERFACE_TYPE_TO must be an interface type.

OBJECT_TYPE_FROM must be a class type or an interface type.

The following check is performed on every instance method of OBJECT_TYPE_FROM.

If an instance method of INTERFACE_TYPE_TO has the required method attribute, OBJECT_TYPE_FROM or one of its super classes must have a method with the same name.

If OBJECT_TYPE_FROM or one of its super classes has an instance method(this is named METHOD_FROM) with the same name as an instance method of INTERFACE_TYPE_TO, METHOD_FROM must be an instance method and satisfy the interface method requirement.

Interface Method Requirement

The interface method requirement is the requirement whether a method is able to be assigned to an interface method.

  INTERFACE_METHOD_TO = METHOD_FROM

This is a concept that converts the type-to-type assignment explained in Assignment Requirement to method-to-method assignment.

INTERFACE_METHOD_TO must be an instance method.

METHOD_FROM must be an instance method.

The length of the arguments of the method of the INTERFACE_METHOD_TO type must be greater than or equal to the length of the required arguments the method of the INSTANT_METHOD_TYPE_FROM type.

The every argument other than at 0 index of the method of the INSTANT_METHOD_TYPE_FROM must satisfy the assignment requirement to the argument as the same index of the method of the INTERFACE_METHOD_TO without a data conversion and with interface exactly matched.

The return type of the method of the INSTANT_METHOD_TYPE_FROM must must satisfy the assignment requirement to the return type of the method of the INTERFACE_METHOD_TO without a data conversion and with interface exactly matched.

See Also

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License