- 浏览: 3048890 次
- 性别:
- 来自: 海外
文章分类
- 全部博客 (430)
- Programming Languages (23)
- Compiler (20)
- Virtual Machine (57)
- Garbage Collection (4)
- HotSpot VM (26)
- Mono (2)
- SSCLI Rotor (1)
- Harmony (0)
- DLR (19)
- Ruby (28)
- C# (38)
- F# (3)
- Haskell (0)
- Scheme (1)
- Regular Expression (5)
- Python (4)
- ECMAScript (2)
- JavaScript (18)
- ActionScript (7)
- Squirrel (2)
- C (6)
- C++ (10)
- D (2)
- .NET (13)
- Java (86)
- Scala (1)
- Groovy (3)
- Optimization (6)
- Data Structure and Algorithm (3)
- Books (4)
- WPF (1)
- Game Engines (7)
- 吉里吉里 (12)
- UML (1)
- Reverse Engineering (11)
- NSIS (4)
- Utilities (3)
- Design Patterns (1)
- Visual Studio (9)
- Windows 7 (3)
- x86 Assembler (1)
- Android (2)
- School Assignment / Test (6)
- Anti-virus (1)
- REST (1)
- Profiling (1)
- misc (39)
- NetOA (12)
- rant (6)
- anime (5)
- Links (12)
- CLR (7)
- GC (1)
- OpenJDK (2)
- JVM (4)
- KVM (0)
- Rhino (1)
- LINQ (2)
- JScript (0)
- Nashorn (0)
- Dalvik (1)
- DTrace (0)
- LLVM (0)
- MSIL (0)
最新评论
-
mldxs:
虽然很多还是看不懂,写的很好!
虚拟机随谈(一):解释器,树遍历解释器,基于栈与基于寄存器,大杂烩 -
HanyuKing:
Java的多维数组 -
funnyone:
Java 8的default method与method resolution -
ljs_nogard:
Xamarin workbook - .Net Core 中不 ...
LINQ的恶搞…… -
txm119161336:
allocatestlye1 顺序为 // Fields o ...
最近做的两次Java/JVM分享的概要
先看看下面这个代码例子,
(1)与(2)分别应该调用哪个版本的方法呢?
Java 8的接口上的default method,或者叫virtual extension method,目的是为了让接口可以“事后”添加新方法而无需强迫所有实现该接口的类都提供新方法的实现。也就是说它的主要使用场景可能会涉及“代码演进”。
所以让我们把例子退回到代码演进的更早阶段。或许以前这段代码是这样的:
此时的(1)处会调用到Foo.bar(long)方法。
但是当IFoo新添加了新方法bar(int)并提供默认实现之后,(1)就会被“劫持”到IFoo.bar(int)的默认实现上,因为这个版本的signature提供了更准确的匹配。
这种“劫持”行为似乎很符合Java的一贯语义,但是很容易给码农挖坑啊orz…
当前版本的Java 8语言规范草案:http://cr.openjdk.java.net/~mr/se/8/java-se-8-fr-spec-01/java-se-8-jls-fr-diffs.pdf
interface IFoo { default void bar(int i) { System.out.println("IFoo.bar(int)"); } } public class Foo implements IFoo { public static void main(String[] args) { Foo foo = new Foo(); foo.bar(42); // (1) invokevirtual Foo.bar(int)void IFoo ifoo = foo; ifoo.bar(42); // (2) invokeinterface IFoo.bar(int)void } public void bar(long l) { System.out.println("Foo.bar(long)"); } }
(1)与(2)分别应该调用哪个版本的方法呢?
Java 8的接口上的default method,或者叫virtual extension method,目的是为了让接口可以“事后”添加新方法而无需强迫所有实现该接口的类都提供新方法的实现。也就是说它的主要使用场景可能会涉及“代码演进”。
所以让我们把例子退回到代码演进的更早阶段。或许以前这段代码是这样的:
interface IFoo { } public class Foo implements IFoo { public static void main(String[] args) { Foo foo = new Foo(); foo.bar(42); // (1) invokevirtual Foo.bar(long)void } public void bar(long l) { System.out.println("Foo.foo(long)"); } }
此时的(1)处会调用到Foo.bar(long)方法。
但是当IFoo新添加了新方法bar(int)并提供默认实现之后,(1)就会被“劫持”到IFoo.bar(int)的默认实现上,因为这个版本的signature提供了更准确的匹配。
这种“劫持”行为似乎很符合Java的一贯语义,但是很容易给码农挖坑啊orz…
当前版本的Java 8语言规范草案:http://cr.openjdk.java.net/~mr/se/8/java-se-8-fr-spec-01/java-se-8-jls-fr-diffs.pdf
发表评论
-
The Prehistory of Java, HotSpot and Train
2014-06-02 08:18 0http://cs.gmu.edu/cne/itcore/vi ... -
MSJVM and Sun 1.0.x/1.1.x
2014-05-20 18:50 0当年的survey paper: http://www.sym ... -
Sun JDK1.4.2_28有TieredCompilation
2014-05-12 08:48 0原来以前Sun的JDK 1.4.2 update 28就已经有 ... -
IBM JVM notes (2014 ver)
2014-05-11 07:16 0Sovereign JIT http://publib.bou ... -
class data sharing by Apple
2014-03-28 05:17 0class data sharing is implement ... -
Java 8与静态工具类
2014-03-19 08:43 16275以前要在Java里实现所谓“静态工具类”(static uti ... -
HotSpot Server VM与Server Class Machine
2014-02-18 13:21 0HotSpot VM历来有Client VM与Server V ... -
Java 8的lambda表达式在OpenJDK8中的实现
2014-02-04 12:08 0三月份JDK8就要发布首发了,现在JDK8 release c ... -
GC stack map与deopt stack map的异同
2014-01-08 09:56 0两者之间不并存在包含关系。它们有交集,但也各自有特别的地方。 ... -
HotSpot Server Compiler与data-flow analysis
2014-01-07 17:41 0http://en.wikipedia.org/wiki/Da ... -
字符串的一般封装方式的内存布局 (1): 元数据与字符串内容,整体还是分离?
2013-11-07 17:44 22394(Disclaimer:未经许可请 ... -
字符串的一般封装方式的内存布局
2013-11-01 12:55 0(Disclaimer:未经许可请 ... -
关于string,内存布局,C++ std::string,CoW
2013-10-30 20:45 0(Disclaimer:未经许可请 ... -
对C语义的for循环的基本代码生成模式
2013-10-19 23:12 21873之前有同学在做龙书(第二版)题目,做到8.4的练习,跟我对答案 ... -
Java的instanceof是如何实现的
2013-09-22 16:57 0Java语言规范,Java SE 7版 http://docs ... -
oop、klass、handle的关系
2013-07-30 17:34 0oopDesc及其子类的实例 oop : oopDesc* ... -
Nashorn各种笔记
2013-07-15 17:03 0http://bits.netbeans.org/netbea ... -
《深入理解Java虚拟机(第二版)》书评
2013-07-08 19:19 0值得推荐的中文Java虚拟机入门书 感谢作者赠与的样书,以下 ... -
豆列:从表到里学习JVM实现
2013-06-13 14:13 48364刚写了个学习JVM用的豆列跟大家分享。 豆列地址:http: ... -
hotspot: print heap layout
2013-05-28 10:46 0VM vm = VM.getVM(); CollectedH ...
相关推荐
8. **".java"源文件中是否可以包括多个类**: - 可以包含多个类,但只能有一个公共类(public class),且文件名必须与公共类名一致。 - 其他类可以是默认访问级别,即不使用任何访问修饰符声明。 9. **char型...
Device Model Description=IEC 61966-2.1 Default RGB colour space - sRGB Viewing Conditions Description=Reference Viewing Condition in IEC61966-2.1 Viewing Conditions=view (0x76696577): 36 bytes ...
/// This is default constructor of the EXIF class. /// public EXIF() { } /// /// This is base constructor of the EXIF class. /// public EXIF(string filePath) { _picture = Image.From...
This is a better resolution of Bug 7376. * Turn off the default of automatically base64 encoding strings that can generate fatal errors in PHP's SAX parser. The automatic base64 encoding can be ...
-units type the units of image resolution -verbose print detailed information about the image -view FlashPix viewing transforms -virtual-pixel method virtual pixel access method -weight type ...
Fixed global scope resolution operator (::) being changed to a single colon in Extract Method. (case=18573) 8021 Extract Method no longer offers to extract to source file when no source file is ...
* Fixed global scope resolution operator (::) being changed to a single colon in Extract Method. (case=18573) 8021 * Extract Method no longer offers to extract to source file when no source file is ...
Chapter 8—CI systems 8.1. Introduction 8.2. Fuzzy encoding in evolutionary computing 8.2.1. Direct methods of fuzzy encoding 8.2.2. Weak encoding with fuzzy sets 8.3. Fuzzy crossover ...
Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are always compiled as aligned. The ACPI_OPERAND_OBJECT has been manually optimized to be aligned and will not work ...
******************************************* ************ WPTOOLS 6 History ************ ... also when scaled and also in high resolution rendering mode. + new code to draw dotted lines ...
PEP 529: Change Windows filesystem encoding to UTF-8 PEP 528: Change Windows console encoding to UTF-8 PEP 520: Preserving Class Attribute Definition Order PEP 468: Preserving Keyword Argument ...
* added support for MKV "SRT/UTF8", "SRT/ASCII", "ASS" and "SSA" subtitles * increased some internal buffers to avoid AC3 overflow in the "thd ac3 joiner" * fixed: frame counting didn't work for MKV ...
■Chapter 8: Getting Fancy with Lists Getting to First Base A Dynamic Presentation Better Stronger Faster Using convertView Using the Holder Pattern Making a List And Checking It Twice Adapting ...
int inc = 8; int iline = 0; for (int i = 0; i ; i++) { int line = i; if (interlace) { if (iline >= ih) { pass++; switch (pass) { case 2 : iline = 4; break; case 3 : iline = 2; inc = 4; ...
14.2.8. RealPath 14.2.9. StringToLower 14.2.10. StringToUpper 14.2.11. StringTrim 14.2.12. StripTags 14.3. 过滤器链 14.4. 编写过滤器 14.5. Zend_Filter_Input 14.5.1. Declaring Filter and ...
In addition to the default Bochs method using the CTRL key and the middle mouse button there are now the choices: - CTRL+F10 (like DOSBox) - CTRL+ALT (like QEMU) - F12 (replaces win32 'legacyF12'...
Update method:=系统升级: Select...=浏览... Progress:=升级进度: Update begin=升级 Cancel=取消 Restart=重启设备 Recovery=恢复系统 WEB Update=网站升级 File Update=文件升级 Device is busing refuse update ...
- **Dynamic Method Resolution(动态方法解析)**:探讨了Objective-C中动态方法解析的过程,即如何确定调用哪个方法实现。 - **Dot Syntax(点语法)**:说明了点语法在Objective-C中的使用,它是一种更简洁的...
- A printer to run the printer test, set-up as the default printer in Windows. - A CD ROM + 1 Music CD or Data CD to run the CD test. - A CD-RW to run the CD burn test. - A network connection and the ...