简体   繁体   English

这两种类初始化方法有什么区别?

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

I'm new to Android. 我是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()), 创建一个新的Jamba应用程序实例,并将其分配给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. 然后获取当前应用程序(或任何getApplication()返回的内容)并将其强制转换为JambaApplication(这可能会引发强制转换错误),然后将其分配给Jamba。

You should study some java though since this is basic java. 您应该学习一些Java,尽管这是基本的Java。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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