V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  JasonLaw  ›  全部回复第 30 页 / 共 36 页
回复总数  714
1 ... 22  23  24  25  26  27  28  29  30  31 ... 36  
2020-09-30 14:13:51 +08:00
回复了 JasonLaw 创建的主题 宠物 想买一款不脏手的🐶🐶拾便器,求推荐
@whileFalse #10 可以分享商品链接吗?
2020-09-30 10:55:39 +08:00
回复了 JasonLaw 创建的主题 宠物 想买一款不脏手的🐶🐶拾便器,求推荐
@whileFalse #4
@jy02201949 #5

标题和内容不太好,其实就是想看一下大家有没有推荐的拾便器,便携又不用清理的。
@javlib 不知道🤣
@mind3x 如果对“a reference to a static field”是这样理解的话,那句话的确是对的。我的关注点是 source code,而你的是 compiled code 。总之谢谢你的回复。
@Jooooooooo #19 其实 Inside the Java Virtual Machine 还是很好的,现在看了 Chapter 5-7,只发现了这一个错误,其他的都解释得很好。
@mind3x #14 你说“A reference to a static field (§8.3.1.1) causes initialization of only the class or interface that actually declares it”来源于官方文档,一定是正确的。难道“a field that is both static and final, and initialized by a compile-time constant expression”不是一个“static field”?

比如我将 NewbornBaby 改为下面这样:

```
class NewbornBaby extends NewParent {

static int hoursOfCrying = 6 + (int) (Math.random() * 2.0);

static final int hoursOfSleep = 6; // a field that is both static and final, and initialized by a compile-time constant expression

static {
System.out.println("NewbornBaby was initialized.");
}
}
```

运行 java -verbose Example2,可以看出 NewbornBaby 被没有被 loaded 。
@mind3x #14
@mind3x #15

“为什么 NewParent 先于 NewbornBaby 被 loaded”是我自己没有认真看清楚的问题,我的核心问题并不是这个,我的核心问题是“为什么 NewbornBaby need not be loaded”。关于这个问题,Holger 在 Stack Overflow 上面回答我了,具体可以看看第 2 条附言。
@Jooooooooo #4 子类还是要先被 loaded 的,只是父类先被 loaded 完成,具体可以看看第 2 条附言。
@ik2h #10 我感觉,我们根本不是在讨论一个东西,相关的回复也没有什么上下文关系。
@Jooooooooo #11 "int hours = NewbornBaby.hoursOfSleep;"对应的字节码为"getstatic #2 和 istore_1"。在 constant pool 中,index 为 2 的 entry 是一个 CONSTANT_Fieldref_info,通过 CONSTANT_Fieldref_info 中的 class_index 最后会得到 NewbornBaby,通过 CONSTANT_Fieldref_info 中的 name_and_type_index,最后会得到一个 CONSTANT_NameAndType_info,通过 CONSTANT_NameAndType_info 中的 name_index 最后会得到 hoursOfSleep,通过 CONSTANT_NameAndType_info 中的 descriptor_index 最后会得到 I 。

然后呢?为什么父类先于子类被 loaded ?子类没有先被 loaded,JVM 是怎么知道子类的父类是什么呢?
@Jooooooooo #4 你可以看看第一条附言。既然子类没有先被 loaded,JVM 是怎么知道子类的父类是什么呢?
@ik2h #6 是的,所以“A reference to a static field (§8.3.1.1) causes initialization of only the class or interface that actually declares it”不一定正确呀。难道“a field that is both static and final, and initialized by a compile-time constant expression”不是一个“static field”?
@ik2h #3 先抛开其他的,单纯讨论 3 楼所引用的内容。

“A reference to a static field (§8.3.1.1) causes initialization of only the class or interface that actually declares it”不一定正确。主题正文中的外链(因为提示回复不能包含外链,所以只能这么弄)说了“A use of a field that is both static and final, and initialized by a compile-time constant expression, is not an active use of the type that declares the field.”,其中的 Example3 也演示了(虽然 Example3 中引用了 Angry.greeting 和 Dog.greeting,但是 Angry 和 Dog 都没有被初始化)。

还是我哪里理解错了?
@ik2h #1 你说的都是关于 initialization 的,而我的问题是关于 loading 的。

顺便说一下,“javac 会为每个类自动生成一个类初始化方法”不是完全正确的。

关于什么情况会产生()方法,https://www.artima.com/insidejvm/ed2/lifetype4.html 中描述了很清楚,以下是一些片段:

Not all classes will necessarily have a () method in their class file. If a class declares no class variables or static initializers, it won't have a () method. If a class declares class variables, but doesn't explicitly initialize them with class variable initializers or static initializers, it won't have a () method. If a class contains only class variable initializers for static final variables, and those class variable initializers use compile-time constant expressions, that class won't have a () method. Only those classes that actually require Java code to be executed to initialize class variables to proper initial values will have a class initialization method.

Interfaces may also be awarded a () method in the class file. All fields declared in an interface are implicitly public, static, and final and must be initialized with a field initializer. If an interface has any field initializers that don't resolve at compile-time to a constant, that interface will have a () method.
2020-09-03 19:06:35 +08:00
回复了 zyfsuzy 创建的主题 macOS 谁有 navicat15 mac 版激活码,请他喝咖啡
更可笑的是这么多人帮忙出谋划策😷
我明白了,我 javac Example3c.java 之后,`javap -c Example3c.class `的输出结果如下所示:

Compiled from "Example3c.java"
class Example3c {
Example3c();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return

public static void addAndPrint();
Code:
0: iconst_1
1: ldc2_w #2 // double 88.88d
4: invokestatic #4 // Method addTwoTypes:(ID)D
7: dstore_0
8: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
11: dload_0
12: invokevirtual #6 // Method java/io/PrintStream.println:(D)V
15: return

public static double addTwoTypes(int, double);
Code:
0: iload_0
1: i2d
2: dload_1
3: dadd
4: dreturn
}

注意“1: i2d”,https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html 中的对 i2d 的描述是“Convert int to double”,这也就是为什么 operand stack 需要 four words 的原因。因为不是存储一个 int 和一个 double,是要存储两个 double 。
2020-09-01 21:11:08 +08:00
回复了 JasonLaw 创建的主题 Java 关于 StackOverflowError 和 OutOfMemoryError 的疑惑
@251 #7 我没有说 CRVV 说的有问题,很多回复说的都是对的。但是对的不代表回答了我的问题,我没有说它们的内容是错的,我说的是很多回复都是答非所问,基本并没有正面回答我的两个疑问,而我的疑问更多的是关于书本所说内容的正确性。

如果你觉得“If there is no space for a new stack frame then, the StackOverflowError is thrown by the Java Virtual Machine (JVM).”跟“请求的栈深度大于虚拟机所允许的最大深度”相等的话,那我无话可说。
2020-09-01 10:54:19 +08:00
回复了 JasonLaw 创建的主题 Java 关于 StackOverflowError 和 OutOfMemoryError 的疑惑
说句不好听的话,我感觉回复总是出现一些答非所问,还是希望大家认真阅读题目,然后再回答。如果是我自己没有描述清楚的话,可以直接在回复里面沟通。
2020-08-31 20:31:58 +08:00
回复了 JasonLaw 创建的主题 Java 关于 StackOverflowError 和 OutOfMemoryError 的疑惑
vincenttone 所说的内容来源于 https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html 中的 “2.5.2. Java Virtual Machine Stacks”
2020-08-28 13:14:44 +08:00
回复了 JasonLaw 创建的主题 MySQL 为什么阿里巴巴的 Java 开发手册说 text 要独立出来一张表?
@Aresxue #35 我在主题正文就已经说了 COMPACT Row Format 。什么叫不要照本宣科?难道你所说的东西不用有官方文档的支撑吗?如果你的答案是不用的话,那没什么了。

还有,你在 27 楼说“对于 innodb 来说 varchar 会和其他列存在一起”,假定你使用的是 DYNAMIC Row Format,有什么材料可以证明你所说的吗?反正我在 https://dev.mysql.com/doc/refman/8.0/en/innodb-row-format.html#innodb-row-format-dynamic 看到的是“When a table is created with ROW_FORMAT=DYNAMIC, InnoDB can store long variable-length column values (for VARCHAR, VARBINARY, and BLOB and TEXT types) fully off-page, with the clustered index record containing only a 20-byte pointer to the overflow page.”。
1 ... 22  23  24  25  26  27  28  29  30  31 ... 36  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5555 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 471ms · UTC 07:39 · PVG 15:39 · LAX 00:39 · JFK 03:39
Developed with CodeLauncher
♥ Do have faith in what you're doing.