#2595 Unboxing Literals

SlimerDude Sun 12 Feb 2017

Moving a question to a new topic.

Maru-chan wrote in 430#c26:

Thank you! i would also like to ask about Literals used by fantom...it is stated there that: "The three types Bool, Int, and Float are value-types. These types are not necessarily passed as object references, but rather passed by value on the call stack. When value types are coerced to/from reference types like Obj and Num, the compiler will generate boxing/unboxing operations."

What do you mean boxing/unboxing operations in that statement?

It's talking about Java boxing / unboxing, see:

It is the name given in Java for the the process of converting between the primitive values and their wrapper objects, for example int and Integer. It's a nuisance and a leaky abstraction which throws an NPE if you get it wrong.

In Fantom everything is an Object, so the whole boxing / unboxing thing is a non-issue.

Though behind the scenes for speed optimisations, Fantom does use both primitive values and wrapper objects. Generally, wrapper objects are used for nullable types like Int?, and primitives for non-nullable types such as Int.

Maru-chan Tue 14 Feb 2017

Thank you so much... here's another question about the operators... in your list

Primary: (x) x.y x.y() x->y() x?.y x?.y() x?->y() x[y]

How do we use these primary operations?

SlimerDude Tue 14 Feb 2017

This is a new question, and should really be in its own topic, but...

(x) x.y  // is a cast to x
x.y()    // calls method 'y'
x->y()   // dynamically calls method 'y'
x?.y     // null safe call on slot 'y'
x?.y()   // null safe call on method 'y'
x?->y()  // dynamic null safe call on method 'y'
x[y]     // calls a 'get()' method annotated with @Operator

What specifically did you want to know about them?

Login or Signup to reply.