JAVA规范学习——static成员初始化
class Super { static int taxi = 1729; }
class Sub extends Super {
static { System.out.print("Sub "); }
}
class Test {
public static void main(String[] args) {
System.out.println(Sub.taxi);
}
}
输出:1729
知识要点:
A reference to a class field causes initialization of only the class or interface
that actually declares it, even though it might be referred to through the name of a
subclass, a subinterface, or a class that implements an interface.
也就是说只有使用该类或者接口直接定义的类变量,才会激发该类的初始化;如果使用的是其父类定义的类变量,则子类不会被初始化
interface I {
int i = 1, ii = Test.out("ii", 2);
}
interface J extends I {
int j = Test.out("j", 3), jj = Test.out("jj", 4);
}
interface K extends J {
int k = Test.out("k", 5);
}
class Test {
public static void main(String[] args) {
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s, int i) {
System.out.println(s + "=" + i);
return i;
}
}
输出:
1
j=3
jj=4
3
知识要点:
Initialization of an interface does not, of itself, cause initialization of any of its
superinterfaces.
The reference to J.i is to a field that is a compile-time constant; therefore, it
does not cause I to be initialized. The reference to K.j is a reference to a field
actually declared in interface J that is not a compile-time constant; this causes initialization
of the fields of interface J, but not those of its superinterface I, nor
those of interface K. Despite the fact that the name K is used to refer to field j of
interface J, interface K is not initialized.
相关文档:
我对问题的理解:面试中的一个问题,居然想了半天没有什么头绪,我想还是没有思考,没有积累过。其实完全可以说上一些小细节,比如用StringBuffer代替String,用HashMap代替Hashtable, 乘法操作用位移,尽量复用已有的经过检验的高效代码等等。
下面的文章转载自别的网站,写得很专业,周到, ......
Map、Set、Iterator迭代详解
Map接口定义了四种类型的方法,每个Map都包含这些方法。
equals(Object o)比较指定对象与此Map的等价性。
hashCode()返回此Map的哈希码。
Map定义了几个用于插放和删除元素的变换方法。
remove(Object key) 从Map中删除键和关联的值。
put(object key,Object value) 将指定值与指定键相关 ......
学习了两篇的Runtime类,现在对它有了更深一层的了解,那么我们来看看下面的代码:
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader ;
import java.io.BufferedReader;
public class Exec_Output{
public static void main(String []args)throws IOException,Int ......
在非java虚拟机下运行matlab据说可以扩大内存,启动非java虚拟机下运行 matlab的方法有:
一.
1、右建点matlab快捷方式,选属性 ......
通过Web Service混合.NET和Java技术往往很容易,但Web Service并非是.NET和Java互操作的万灵丹。Web Service在集成独立的跨网络通信的组件时非常有用,在简单的调用/返回情景中,涉及的数据类型数量非常有限,且Web Service是基于标准的,混合.NET和Java技术通常显得很简单,因此有人认为Web Serv ......