Roldak/TIMScript

Implicit constructors

Roldak opened this issue · 0 comments

if a class K has a constructor that takes only 1 argument of type T and that is preceded by the keywork "implicit", an instance of that class can be constructed implicitly by a cast from T to K
exemple :

class MyInt[]{
     implicit new(x: int) => { ... }
     ...
}
...
def test(t: MyInt) => { ... }
...
test(2) // implicit construction of MyInt with argument 2. equivalent to test(new MyInt(2))