java中非法的表达式开始什么意思_Java错误:表达式的非法开头

本文探讨了Java中局部变量的定义与使用限制,解释了为何局部变量不能声明为public等访问级别。同时深入介绍了static关键字的作用,包括如何在类中声明静态成员,并通过实例演示了静态成员和实例成员的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

小编典典

方法只能声明局部变量。这就是为什么当您尝试将其声明为public时,编译器会报告错误的原因。

对于局部变量,您不能使用任何类型的访问器(公共,受保护或私有)。

您还应该知道static关键字的含义。在方法中checkYourself,您使用Integer数组locations。

static关键字区分对象创建可访问的元素。因此,它们不是对象本身的一部分。

public class Test { //Capitalized name for classes are used in Java

private final init[] locations; //key final mean that, is must be assigned before object is constructed and can not be changed later.

public Test(int[] locations) {

this.locations = locations;//To access to class member, when method argument has the same name use `this` key word.

}

public boolean checkYourSelf(int value) { //This method is accessed only from a object.

for(int location : locations) {

if(location == value) {

return true; //When you use key word return insied of loop you exit from it. In this case you exit also from whole method.

}

}

return false; //Method should be simple and perform one task. So you can get more flexibility.

}

public static int[] locations = {1,2,3};//This is static array that is not part of object, but can be used in it.

public static void main(String[] args) { //This is declaration of public method that is not part of create object. It can be accessed from every place.

Test test = new Test(Test.locations); //We declare variable test, and create new instance (object) of class Test.

String result;

if(test.checkYourSelf(2)) {//We moved outside the string

result = "Hurray";

} else {

result = "Try again"

}

System.out.println(result); //We have only one place where write is done. Easy to change in future.

}

}

2020-09-16

727907:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [1-2] 727911:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [1-5], path: false<motionCaptureEnable-I32:0==1> 727913:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [2-5], path: false<zoomRatio-F:10.000000<6.000000> 727917:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[pass], innIndex: [3-5], path: true<hybridrawLuxLimiter1-B:1==1> 727918:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [2-2] 727921:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [1-1], path: false<paramsHolder->current_burst_capture_type-I32:-1==2> 727924:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [1-1] 727926:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [1-13], path: false<paramsHolder->current_burst_capture_type-I32:-1==2> 727927:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [2-13], path: (false<zoomRatio-F:10.000000>30.000000>) 727929:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [3-13], path: false<motionCaptureEnable-I32:0==1> 727931:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [4-13], path: false<zoomRatio-F:10.000000<6.000000> 727932:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [5-13], path: (false<hybridrawLuxLimiter2-B:1==0>) 727934:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [6-13], path: (false<hybridrawLuxLimiter2-B:1==0>) 727935:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [7-13], path: (false<hybridrawLuxLimiter2-B:1==0>) 727937:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [8-13], path: (true<hybridrawLuxLimiter1-B:1==1>&&false<paramsHolder->livephoto_enable-B:0==1>) 727940:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [9-13], path: (false<oplusMeta->com.qti.stats_control.hdr_detected-I32:0>0>) 727942:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [10-13], path: (false<oplusMeta->com.qti.stats_control.hdr_detected-I32:0>0>) 727946:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[pass], innIndex: [11-13], path: true<hybridrawLuxLimiter1-B:1==1> 728045:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [1-2] 728047:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [1-5], path: false<motionCaptureEnable-I32:0==1> 728049:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[fail], innIndex: [2-5], path: false<zoomRatio-F:10.000000<6.000000> 728052:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[pass], innIndex: [3-5], path: true<hybridrawLuxLimiter1-B:1==1> 728053:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [2-2] 728056:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[pass], innIndex: [1-1], path: true<paramsHolder->current_burst_capture_type-I32:2==2> 728060:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2677 handlePlanConditions() outIndex: [1-1] 728064:01-01 00:07:18.776 12055 12809 I APS_INTERFACE: [INFO][ ALGO_PREVIEWDECISION ] ApsPreviewDecisionByJsonTree.cpp: 2701 handlePlanConditions() |__[pass], innIndex: [1-13], path: true<paramsHolder->current_burst_capture_type-I32:2==2>
最新发布
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值