简体   繁体   中英

how to assign int to an object of a class

I'm trying to do this;

int number = 1;

Class name = new Class();

Is there any way that I could assign the name object to number 1?, so that I could use methods of name object by typing,

'1. ~~~'

instead of 'name. ~~~' 'name. ~~~' .

What I am trying to do is, the program is going to ask User to put in 'int', and if User put in '1', then User gets to use an object that is assigned to int '1'. But I don't know how to do that.

1 to this object,

2 to another object,

3.. and so on..

No, You can't (assign "simple types" to "objects").

But what is possible and matches your request/description best, is:

/*java.lang.*/Integer number = 1;
//!
/*java.lang.*/Object obj = number; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM