下面两个线程调用有什么区别?这两个电话会同样行事吗?
注意:我没有同时使用#1和#2,这是最好的选择.
private void startConnections(){
ServerThread server = new ServerThread();
server.start(); // #1
Thread serverThread = new Thread(server);
serverThread.start(); //#2
}
class ServerThread extends Thread{
public void run(){}
}
Run Code Online (Sandbox Code Playgroud) 是否有一种在Spring xml配置文件中实现以下功能的捷径.
new MyObject().getData()
Run Code Online (Sandbox Code Playgroud)
代替
Object obj = new MyObject();
obj.getData();
Run Code Online (Sandbox Code Playgroud)
我知道如何在第二种情况下做到这一点.
<bean id="obj" class="MyObject" />
<bean id="data" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject"><ref local="obj" /></property>
<property name="targetMethod"><value>getData</value></property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我相信必须有一种方法可以在一个单一的定义中做到这一点.请建议.
在java中,如果方法有一个最终变量(不是静态的),并且如果我多次调用该方法,那么最终变量在每次调用中都可以有不同的值吗?
public void method1(String msg){
final ArrayList<MessageObject> list = method2(msg);
// code that uses list (example just prints)
}
method1("one")
method1("two") are two calls,
Run Code Online (Sandbox Code Playgroud)
如果method2()为每个输入返回不同的列表,上面的代码是否有效(相对于最终修饰符?)
有没有一种方法可以让Android应用程序在应用程序加载时默认调用内容提供程序,内容提供程序在需要时调用活动.
(content provider's onCreate method在应用程序加载时调用,而不是Activity.onCreate()