转-Cannot refer to an instance field arg while explicitly invoking a constructor
编译失败:
Cannot refer to an instance field arg while explicitly invoking a constructor 调用方法时不能引用一个实例变量
package arkblue.lang.javapuzzler.n53; class Thing {
public Thing(int i) { }
} public class MyThing extends Thing {
private final int arg; public MyThing() {
super(arg = Math.round(12L)); //编译失败
} }
解决办法:使用了交替构造器调用机制(alternate constructor invocation)
在这个私有构造器中,表达式SomeOtherClass.func()的值已经被捕获到了变量i中,并且它可以在超类构造器返回之后存储到final类型的域arg中
class SomeOtherClass {
static int func() {
return Math.round(12L);
}
} public class MyThing extends Thing {
private final int arg; public MyThing() {
this(SomeOtherClass.func());
} private MyThing(int i) {
super(i);
arg = i;
}
}
转-Cannot refer to an instance field arg while explicitly invoking a constructor的更多相关文章
- Cannot refer to an instance field pageTitle while explicitly invoking a cons
当下面这样时在第7行会提示:Cannot refer to an instance field pageTitle while explicitly invoking a cons public cl ...
- Akka源码分析-Actor&ActorContext&ActorRef&ActorCell
分析源码的过程中我们发现,Akka出现了Actor.ActorRef.ActorCell.ActorContext等几个相似的概念,它们之间究竟有什么区别和联系呢? /** * Actor base ...
- Effective Java 31 Use instance fields instead of ordinals
Principle Never derive a value associated with an enum from its ordinal; store it in an instance fie ...
- Effective Java 77 For instance control, prefer enum types to readResolve
The readResolve feature allows you to substitute another instance for the one created by readObject ...
- A const field of a reference type other than string can only be initialized with null Error [duplicate]
I'm trying to create a 2D array to store some values that don't change like this. const int[,] hiveI ...
- android jni ——Field & Method --> Accessing Field
现在我们知道了怎样使用native code访问简单的数据类型和引用参考类型(string,array),下面我们来介绍怎样让jni代码去访问java中的成员变量和成员函数,然后可以再jni中回调ja ...
- 【反射】Reflect Class Field Method Constructor
关于反射 Reflection 面试题,什么是反射(反射的概念)? 主要是指程序可以访问,检测和修改它本身状态或行为的一种能力,并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义 ...
- [转载] google mock cookbook
原文: https://code.google.com/p/googlemock/wiki/CookBook Creating Mock Classes Mocking Private or Prot ...
- 译:Spring框架参考文档之IoC容器(未完成)
6. IoC容器 6.1 Spring IoC容器和bean介绍 这一章节介绍了Spring框架的控制反转(IoC)实现的原理.IoC也被称作依赖注入(DI).It is a process wher ...
随机推荐
- POJ 2932 Coneology(扫描线)
[题目链接] http://poj.org/problem?id=2932 [题目大意] 给出N个两两没有公共点的圆,求所有不包含于其它圆内部的圆 [题解] 我们计算出所有点在圆心所有y位置的x值, ...
- 【状态压缩DP】BZOJ1087-[SCOI2005]互不侵犯King
[题目大意] 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. [思路] 先预处理每一行可行的状态 ...
- Linux虚拟机小问题解决方法系列
1)使用虚拟机的过程中,会碰到虚拟机占用的空间越来越大的情况,即使删除了虚拟机里的文件,磁盘空间还是似乎还是没有释放,使用“vmware-vdiskmanager”工具解决.解决方法在这里:参考.合并 ...
- [OpenJudge8462][序列DP]大盗阿福
大盗阿福 总时间限制: 1000ms 内存限制: 65536kB [描述] 阿福是一名经验丰富的大盗.趁着月黑风高,阿福打算今晚洗劫一条街上的店铺. 这条街上一共有 N 家店铺,每家店中都有一些现金. ...
- 解密所有APP运行过程中的内部逻辑(转)
转贴地址:http://www.freebuf.com/tools/54562.html 0×01前言 这年头,apk 全都是加密啊,加壳啊,反调试啊,小伙伴们表示已经不能愉快的玩耍了.静态分析越来越 ...
- 学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础
第 2 章: 单表查询 use TSQLFundamentals2008; select * from Sales.orders; select empid, year(orderdate) as o ...
- Word中对象显示不完整
选中上下文字后,右键没有段落,如果是图片的话是有的,那么我们可以点击菜单栏中段落的右下三角,在那设置单倍行距.
- ajax asynx:false
默认设置下,所有请求均为异步请求.如果需要发送同步请求,请将此选项设置为 false.注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行 (默认: true) 默认设置下,所有请求均为 ...
- 轻松加愉快的 Kubernetes 安装教程
轻松加愉快的 Kubernetes 安装教程 马哥Linux运维 2 days ago 作者:无聊的学习者 来源:见文末 在国内安装 K8S,一直是大家很头痛的问题,各种麻烦,关键是还不知道需要下载什 ...
- Font Awesome:图标字体,完全CSS控制
Font Awesome是一种web font,它包含了几乎所有常用的图标,比如Twitter.facebook等等.用户可以自定义这些图标字体,包括大小.颜色.阴影效果以及其它可以通过CSS控制的属 ...