简体   繁体   中英

What's the difference between these two approaches to class initialization?

I'm new to Android. Can someone explain the difference between these two approaches to class initialization?

jamba = new JambaApplication(); 
jamba = (JambaApplication)  getApplication();

One creates a new instance of Jamba Application and assigns it to Jamba (= new JambaApplication()),

And one gets the current application (or whatever getApplication() returns) and casts it to a JambaApplication (which may throw casting errors), and assigns it to Jamba.

You should study some java though since this is basic java.

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