﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-kooyee ‘s blog-随笔分类-Groovy on Grails</title><link>http://www.blogjava.net/Javawind/category/29611.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 22 Feb 2008 19:53:59 GMT</lastBuildDate><pubDate>Fri, 22 Feb 2008 19:53:59 GMT</pubDate><ttl>60</ttl><item><title>新的声明方式，用def定义新属性</title><link>http://www.blogjava.net/Javawind/archive/2008/02/23/181543.html</link><dc:creator>kooyee</dc:creator><author>kooyee</author><pubDate>Fri, 22 Feb 2008 16:57:00 GMT</pubDate><guid>http://www.blogjava.net/Javawind/archive/2008/02/23/181543.html</guid><wfw:comment>http://www.blogjava.net/Javawind/comments/181543.html</wfw:comment><comments>http://www.blogjava.net/Javawind/archive/2008/02/23/181543.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Javawind/comments/commentRss/181543.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Javawind/services/trackbacks/181543.html</trackback:ping><description><![CDATA[def 和 @Property <br />
<br />
旧版本中（Groovy JSR 06 的之前版本）@Property定义一个带有setter和getter的私有属性，而def和java中public一样，定义一个公共的属性。<br />
<br />
后来@Property已经从Groovy JSR 06中移除，在Grails 0.2和之后的版本中也不会再需要它&nbsp;。<br />
<br />
现在def用来定义一个带有setter和getter的私有属性，来代替了@Property。<br />
<br />
<br />
<br />
参考：http://docs.codehaus.org/display/GroovyJSR/Property+proposal<br />
<br />
<table class="confluenceTable">
    <tbody>
        <tr>
            <th class="confluenceTh">symbol </th>
            <th class="confluenceTh">&nbsp;meaning </th>
        </tr>
        <tr>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;private </td>
        </tr>
        <tr>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_yellow.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;protected </td>
        </tr>
        <tr>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;public </td>
        </tr>
        <tr>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_blue.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;final </td>
        </tr>
    </tbody>
</table>
<br />
<br />
<table class="confluenceTable">
    <tbody>
        <tr>
            <th class="confluenceTh">code </th>
            <th class="confluenceTh">field </th>
            <th class="confluenceTh">&nbsp; getter </th>
            <th class="confluenceTh">&nbsp; setter </th>
        </tr>
        <tr>
            <td class="confluenceTd">def x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">final x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_blue.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">public x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">protected x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_yellow.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">private x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">public final x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_blue.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">@Property x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
        </tr>
        <tr>
            <td class="confluenceTd">other permutations? </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
    </tbody>
</table>
<h2><a name="Propertyproposal-Proposed"></a>Proposed</h2>
<table class="confluenceTable">
    <tbody>
        <tr>
            <th class="confluenceTh">code </th>
            <th class="confluenceTh">field </th>
            <th class="confluenceTh">&nbsp; getter </th>
            <th class="confluenceTh">&nbsp; setter </th>
            <th class="confluenceTh">note </th>
        </tr>
        <tr>
            <td class="confluenceTd">def x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">final x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_blue.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">the field doesn't need to be final IMHO (dk) My view is that the field should be final(tug) <br clear="all" />
            </td>
        </tr>
        <tr>
            <td class="confluenceTd">public x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">protected x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_yellow.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">private x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
        </tr>
        <tr>
            <td class="confluenceTd">public final x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_blue.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd"><br clear="all" />
            </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">a public final field like in Java <br clear="all" />
            </td>
        </tr>
        <tr>
            <td class="confluenceTd">@Property x </td>
            <td class="confluenceTd"><img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_red.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp; <img class="emoticon" height="16" alt="" src="http://docs.codehaus.org/images/icons/emoticons/star_green.gif" width="16" align="absMiddle" border="0" /> </td>
            <td class="confluenceTd">&nbsp;if it's still supported (MrG) My proposal is to remove it (tug) <br clear="all" />
            </td>
        </tr>
        <tr>
            <td class="confluenceTd">other permutations? </td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;</td>
            <td class="confluenceTd">&nbsp;what happens with static? (MrG) Static behave exactly the same(tug) <br clear="all" />
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/Javawind/aggbug/181543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Javawind/" target="_blank">kooyee</a> 2008-02-23 00:57 <a href="http://www.blogjava.net/Javawind/archive/2008/02/23/181543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>