Userland autoboxing?

后端 未结 1 1853
日久生厌
日久生厌 2021-01-13 09:29

Is it possible to implement autoboxing for your own classes?

To illustrate my example, this is what I might want to write:

Foo foo = \"lolcat\";


        
相关标签:
1条回答
  • 2021-01-13 10:11

    No, java does not support operator overloading (http://en.wikipedia.org/wiki/Operator_overloading).

    Autoboxing is a compiler feature and not available for your own classes.

    The reasoning is explained here: http://www.cafeaulait.org/javafaq.html#xtocid1902938

    0 讨论(0)
提交回复
热议问题