V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
V2EX  ›  JasonLaw  ›  全部回复第 31 页 / 共 37 页
回复总数  739
1 ... 23  24  25  26  27  28  29  30  31  32 ... 37  
2020 年 10 月 10 日
回复了 JasonLaw 创建的主题 程序员 有方法实现 Selenium 单个 WebDriver 多标签/线程爬取吗?
@chaogg #4 就算是使用多个 tab,单个 WebDriver 还是单线程的,无法做到一个线程对应一个 tab 。最后还是要启动多个 WebDriver 实现并发。
2020 年 10 月 10 日
回复了 JasonLaw 创建的主题 程序员 有方法实现 Selenium 单个 WebDriver 多标签/线程爬取吗?
@chaogg #1 也就是没有办法实现?但是一台电脑能够打开的浏览器个数很有限,请问有没有好的方法解决这个问题?
2020 年 10 月 10 日
回复了 JasonLaw 创建的主题 算法 为什么 Bellman–Ford 算法需要循环“顶点个数 - 1”次呢?
@litmxs 感觉你说的“ 因为每次的松弛操作都可以保证从一个结点到其相邻结点的最短路估计值达到最短路的实际值,也就是保证了所有深度为 1 的路径最短。n 次操作则可以保证所有深度为 n 的路径最短。”怪怪的,但是我又说不太上来是哪里有问题,替换为“ After the i-th iteration of the outer loop, the shortest paths with at most i edges are calculated.”会更好理解。
2020 年 10 月 10 日
回复了 JasonLaw 创建的主题 算法 为什么 Bellman–Ford 算法需要循环“顶点个数 - 1”次呢?
@lidlesseye11 对,而且可以通过这个 loop invariant 证明算法的正确性。
2020 年 10 月 9 日
回复了 JasonLaw 创建的主题 算法 为什么 Bellman–Ford 算法需要循环“顶点个数 - 1”次呢?
@lidlesseye11 #2 我说的“不变性( invariant )”其实是 loop invariant -https://stackoverflow.com/questions/3221577/what-is-a-loop-invariant
2020 年 9 月 30 日
回复了 JasonLaw 创建的主题 宠物 想买一款不脏手的🐶🐶拾便器,求推荐
@whileFalse #10 可以分享商品链接吗?
2020 年 9 月 30 日
回复了 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 年 9 月 3 日
回复了 zyfsuzy 创建的主题 macOS 谁有 navicat15 mac 版激活码,请他喝咖啡
更可笑的是这么多人帮忙出谋划策😷
1 ... 23  24  25  26  27  28  29  30  31  32 ... 37  
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2643 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 25ms · UTC 15:55 · PVG 23:55 · LAX 08:55 · JFK 11:55
♥ Do have faith in what you're doing.