The goal of the type system is to encourage local abstraction, generalization, and explicitness.
local abstraction: "structural typing" will isolate the abstraction locally.
generalization: "function overloading" allow reuse the same procedure with a slight deviation.
explicitness: no implicit auto conversation between nominal types; use generic type parameter to constraint valid input set. the constraint can be reused as an interface.
The built-in primitive type and imported java type are "nominal".
The function and interface are "structurally typed". When function referenced as type, an implicit interface will be defined as the same name, covering all variants of the function.
[type1, type2], type[] and {[key: keyType]: valueType} are type operator to construct new type from existing type either the type is nominal or structural.
Builtin Primitive Type
bool: same as java.lang.Boolean
int8
uint8
int16
uint16
int32
uint32
int64
uint64
float32
float64
string
Java Type
java type can be imported by import statement
All java array types
All java interface types
All java class types
All java enum types
[1, 2, 3] => ArrayList<Long>
{'a': 1, 'b': 2} => HashMap<String, Long>
As function argument
function SayHello(msg: string) {
}
Construct new instance by
out := StringBuilder{}
Java interface can not create new instance, can be used as argument type and variable type
DexScript Function Type
defined by any function
function Hello() {}
function can have overload by its argument type
function Hello(arg: int32) {}
function Hello(arg: int64) {}
function can have overload by where
function IsVip(customer): boolean {
return customer.name() == 'abc'
}
function Hello(customer) where IsVip(customer) {}
The goal of the type system is to encourage local abstraction, generalization, and explicitness.
The built-in primitive type and imported java type are "nominal".
The function and interface are "structurally typed". When function referenced as type, an implicit interface will be defined as the same name, covering all variants of the function.
[type1, type2]
,type[]
and{[key: keyType]: valueType}
are type operator to construct new type from existing type either the type is nominal or structural.Builtin Primitive Type
java.lang.Boolean
Java Type
java type can be imported by
import
statement[1, 2, 3]
=>ArrayList<Long>
{'a': 1, 'b': 2}
=>HashMap<String, Long>
As function argument
Construct new instance by
Java interface can not create new instance, can be used as argument type and variable type
DexScript Function Type
defined by any function
function can have overload by its argument type
function can have overload by
where
DexScript Interface Type
defined by interface keyword
If we have defined a function
This will make
string
implements the interfaceSayable
. One interface can require multiple functions available:The interface can also depend on the value
interface can also take type argument
interface can be constrained
the
<>
is partial construction, only applies to interface. the{}
is complete construction.Magic Function
Following function names have special meaning
{}
such asSomeFunc{}
()
sucha asSomeFunc()
<-
+
-
*
/
[]
This will make dexscript function or java types implement some dexscript interface automatically.
Await
this will make
World
implement this interfaceUniform Function Call
a.b()
is same asb(a)