<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Using Class as an annotation attribute type</title>
	<link>http://tech.puredanger.com/2007/05/25/class-in-annotation/</link>
	<description>Alex Miller's technical blog</description>
	<pubDate>Thu, 20 Nov 2008 15:49:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Bruce Chapman</title>
		<link>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3887</link>
		<pubDate>Mon, 28 May 2007 01:16:10 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3887</guid>
					<description>bastard feedback system that doesn't tell you whether its going to eat your less thans or not.

here's another attempt at the munged line

Class&amp;#60;? extends ValueStringAdapter&amp;#60;?&amp;#62;&amp;#62; value();</description>
		<content:encoded><![CDATA[<p>bastard feedback system that doesn&#8217;t tell you whether its going to eat your less thans or not.</p>
<p>here&#8217;s another attempt at the munged line</p>
<p>Class&lt;? extends ValueStringAdapter&lt;?&gt;&gt; value();
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bruce Chapman</title>
		<link>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3886</link>
		<pubDate>Mon, 28 May 2007 01:03:01 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3886</guid>
					<description>For those that can't follow the above comments...

The  annotation currently would allow a value of Long.class which would then blow up at run time.

You can used a bounded wildcard in your annotation type declaration to enforce that the class is some type of ValueStringAdapter thus

Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Adapter {
    Class&amp;#62; value();
}</description>
		<content:encoded><![CDATA[<p>For those that can&#8217;t follow the above comments&#8230;</p>
<p>The  annotation currently would allow a value of Long.class which would then blow up at run time.</p>
<p>You can used a bounded wildcard in your annotation type declaration to enforce that the class is some type of ValueStringAdapter thus</p>
<p>Retention(RetentionPolicy.RUNTIME)<br />
@Target(ElementType.METHOD)<br />
public @interface Adapter {<br />
    Class&gt; value();<br />
}
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Alex</title>
		<link>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3878</link>
		<pubDate>Sun, 27 May 2007 15:37:54 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3878</guid>
					<description>Thanks Stefan.  I did actually use a parameterized Class in my code, but I thought it muddied the example a bit.  I guess I should have mentioned it....</description>
		<content:encoded><![CDATA[<p>Thanks Stefan.  I did actually use a parameterized Class in my code, but I thought it muddied the example a bit.  I guess I should have mentioned it&#8230;.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Stefan Schulz</title>
		<link>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3875</link>
		<pubDate>Sun, 27 May 2007 14:07:53 +0000</pubDate>
		<guid>http://tech.puredanger.com/2007/05/25/class-in-annotation/#comment-3875</guid>
					<description>I remember to have used classes in annotations at work. The main problem with it, as you said, is the tight binding you get to the class. I usually prefer to use classes over textual references though, whenever possible. IIRC, eclipse offers checking for such textual references on refactoring, so it's not too bad. But usually, one will see the errors at runtime and no earlier.
One remark, Eugene made a valid point on your approach on his blog*, and I wonder why he didn't comment on it here, too. It's in general about generic usage of Class, which allows for type-safe restriction of the class to be passed. It should at least be a Class but of course the more specific the better.
 *)http://www.jroller.com/page/eu?entry=class_parameters_in_annotations,</description>
		<content:encoded><![CDATA[<p>I remember to have used classes in annotations at work. The main problem with it, as you said, is the tight binding you get to the class. I usually prefer to use classes over textual references though, whenever possible. IIRC, eclipse offers checking for such textual references on refactoring, so it&#8217;s not too bad. But usually, one will see the errors at runtime and no earlier.<br />
One remark, Eugene made a valid point on your approach on his blog*, and I wonder why he didn&#8217;t comment on it here, too. It&#8217;s in general about generic usage of Class, which allows for type-safe restriction of the class to be passed. It should at least be a Class but of course the more specific the better.<br />
 *)http://www.jroller.com/page/eu?entry=class_parameters_in_annotations,
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
