Conversion from built in types to Custom Classes

前端 未结 3 1382
不知归路
不知归路 2021-01-19 10:54

I have a custom class that acts as an int called Integer, I would like to tell compiler how to convert certain types to Integer automatically so that I can avoid typing same

3条回答
  •  甜味超标
    2021-01-19 11:24

    You could define constructors in Integer for those types you want to implicitly convert. Do not make them explicit.

提交回复
热议问题