Jcat
宠辱不惊,闲看庭前花开花落~~
posts - 173,comments - 67,trackbacks - 0

最后的逗号
String[] strs = {"1", "2", "3", };
System.out.println(strs.length); //3

这竟然是符合语法的!

ArrayInitializer:       
{ [VariableInitializer {, VariableInitializer} [,]] }
VariableInitializer: ArrayInitializer Expression
http://java.sun.com/docs/books/jls/third_edition/html/syntax.html#18.1

"This is good for quick testing. I always use this. In my case, I have a table, sometimes I care some columns, other times I care some other columns, so I am lazy to remove the last comma when I change columns. It's convenient."



运行没有main的java类
      通常我们需要在java类中添加main函数才能在命令行运行这个类,但是有一种(可以让你晕死的)方法可以让你在没有main的情况下也可以运行java class(当然不是用applet),代码如下:

public   class  NoMainMethod
{
    
static
{
        System.out.println(
" Hello word, no main method! " );
        System.exit(
0 );
    }

}

      static语句块会在加载类的时候加载,它在main函数之前运行。 当static语句块运行完毕后,会寻找main函数,如果没有找到,就会抛出异常。但是在以上的代码中,static语句块执行后,我们终止程序的运行,所以异常就不会被抛出啦。


跳出JavaBean的命名规范
      通常,JavaBean的命名规范为:属性名的第二个字母也不能大写。即不可以出现类似 aAndB 这样的属性名。如,Hibernate的PO如果出现这样的名字,将抛出net.sf.hibernate.PropertyNotFoundException异常。但是有一个办法可以解决该问题:

java file:     
private  String aAndB;   
public  String getAAndB()  {        
        
return  aAndB;   
}
   
public   void  setAAndB(String aAndB)  {       
         this .aAndB  =  aAndB;   
}

mapping.xml < property  name ="AAndB"  column ="a_and_b" />
      结研究发现,上述办法可以成功的将aAndB这样的属性与数据库mapping起来。
      显然hibernate是通过setter和getter来访问对象的属性的,所以我们可以说:mapping.xml并不是在类的属性和数据库的字段名之间做映射,而是在setter/getter和数据库的字段之间做映射。
      诚然,即使可以也别这么干,实际工作中,还是规避这种问题的好。 

posted on 2006-08-06 00:27 Jcat 阅读(256) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: