易截截图软件、单文件、免安装、纯绿色、仅160KB

Assert 在Java和Groovy中的区别

对于防御性编程而言,assert一直都是非常重要的工具。但对于熟悉-ea参数的Java程序员而言,当他们看到所有Groovy断言无论是否有-ea都照样执行时一定会非常困惑。
事实上,Groovy的断言是无条件开启的!
对此,开发人员Roshan Dawrani做了如下解释:(原文)
The JDK documentation has a long chapter on assertions that talks about the disabling feature for assertions and its impact on compiling, starting the VM, and resulting design issues. Although this is fine and the design rationale behind Java assertions is clear, we feel the disabling feature is the
biggest stumbling block for using assertions in Java. You can never be sure that your assertions are really executed.
在Core Java(或者是TIJ?记不清了)里,作者提到assertion类似“在海边开赛艇要带好你的卡通救生圈;如果船已经在大海中央,就把救生圈扔掉好了”。不过,在Groovy中,显然这种防御措施会一直跟随你到大海的任意角落(希望不是海底)。
PS:如果仔细看看Groovy断言的输出,你一定会意识到它对于debug是多么有用:
1: def xml = new XmlParser().parseText("x")
2: assert "y" == xml.text()
3: -----
4: output:
5:
6: assert "y" == xml.text()
7: | | |
8: | | x
9: | test[attributes={}; value=[x]]
10: false
11:
******
Quote of the day:
I didn't really say everything I said. - Yogi Berra


相关文档:

分析java dump文件

 
注意,请不要被我误导,我没有看其他资料,这是我自己分析的,有些可能是不对的
 
"DestroyJavaVM" prio=6 tid=0x00316800 nid=0x448 waiting on condition [0x00000000
..0x00a0fd4c]
   java.lang.Thread.State: RUNNABLE
 
"Thread-1" prio=6 tid=0x02f85000 nid=0xd18 waiting for m ......

JAVA经典基础问题之 抽象类与接口

一、抽象类注意事项:
1,抽象类中可以用0+个抽象方法。
2,有抽象方法的的类必须是抽象类。
3,抽象类派生的非抽象子类必须实现抽象类中定义的所有抽象方法。
4,抽象类不能创建对象。
5,abstract 不能与final并列修饰同一个类
6,abstract不能与private,static ,final,native并列修饰同一方法。
package com.wens ......

JAVA的容器 List,Map,Set

JAVA的容器---List,Map,Set
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
Collection接口
  Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements)。一些 Collection允许相 ......

java设计模式一窥1

  Design Patterns in Java
-----------------------------------------
Steven John Metsker 
William C.Wake
-----------------------------------------
龚波等译
--------一、二章读书记录------
模式是集体智慧的结晶。它给出了相关行业中经验丰富的从业者所应用的所有的概念和方 ......

用java写的一个斗地主发牌小程序

package bag;
import java.util.*;
public class Dou {
 /*
  * 生成扑克牌
  */
 public String[] puke() {
  String[] s1 = { "黑桃", "红桃", "梅花", "方片" };
  String[] s2 = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号