在调用另一个方法并在线程运行方法中传递字符串参数时发生此错误。错误是“将titlePartnerF的修饰符更改为final”。 我尝试调用的方法用于发送应在后台运行的推送通知。请帮助...提前感谢
String titlePartnerF= titlePartner;
final MerchantBeanPush pushBeanF = pushBean ;
// MULTHREADING CODE
// KAMLESH DAVE : 03-FEB-2019
Thread t = new Thread(new Runnable() {
public void run() {
/* * Do something inside the thread*/
PushNotifictionHelper.sendPushNotification("W",pushBeanF.getWebToken(),titlePartnerF,messageP, bodyPartner);
}
});
t.start();
System.out.println("we are outside from method now in background+++++++++++");
答案 0 :(得分:0)
内部类中引用的任何变量都必须声明为final或有效地为final。
String titlePartnerF= titlePartner;
必须为final String titlePartnerF= titlePartner;
在这里查看说明:Why Java inner classes require "final" outer instance variables?