Convert from Object to Original Class

后端 未结 2 1667
借酒劲吻你
借酒劲吻你 2020-12-11 22:46

I\'m storing a instance of Entry class in an Object.

Entry newentry = new Entry(j, 0.0);
Object test = newentry;

2条回答
  •  盖世英雄少女心
    2020-12-11 23:22

    First answer:

    Change the datatype of test from Object to Entry in your example.

    Second answer:

    If you really need to assign it to an object (in this case, a variable called "test") somewhere along the way (for some reason) then you can do this to get it back:

    Object val = ((Entry)test).getValue();
    

提交回复
热议问题