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
相关文档:
更改oracle Listener 配置:D:\Oracle\moon\product\11.1.0\db_1\NETWORK\ADMIN 目录之下:Listener.ora文件进行配置:
# listener.ora Network Configuration File: d:\Oracle\moon\product\11.1.0\db_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SI ......
1.Java的代码一般分为两大类:一种是结构定义语句;一种是功能语句(功能语句要用分号结尾)。
2.用/* 内容 */注释,内容里面是不能存在/* */的;但是可以存在//;因为这样就不会发生系统不知道哪个*/才是真的结束符。
3.变量使用前必须初始化,使用单引号的作用就是把里面的字 ......
如果你用的是myeclipse 6.0 而且 在使用
@Override 时出现以下错误:
The method XXXXXX of type XXXXXXXXX must
override a superclass method
那是因为你的Compiler 是jdk1.5,只要把它改为 1.6就可以了
方法:
1. window ->preferences... -> java -> Compiler
2. Compiler compliance lev ......
一 DOM 以下代码用DOM是生成一个XML文档
package xml;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
imp ......
一.项目简介:
JAVA语言是一种可移植的,简单的,健壮的嵌入式语言。并且对网络,数据库有很好的支持,基于JAVA语言的这种特性可以十分容易地建立一个小型INTERNET服务器。
本项目中,作者用JAVA语言编写了一个WEB微型服务器,对简单的HTTP请求进行响应,并通过后端数据库对用户的查询进行处理,从而动态地返回HT ......