Java Virtal Machine.net

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

December/2024
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
222324252627 28
293031    

[ Archives News
for 'Java Technology' ]

home > news > java technology > potd: custom access modifier

POTD: Custom Access Modifier

My project of the day (or "POTD") is Custom Access Modifier — an annotation and an enforcer that lets you define application-defined custom access modifiers, So let me explain this a bit more. Say you have a library that people use, and say you are thinking about deprecating one of the methods. Yes, you can just put @Deprecated, but that doesn't actually prevent people from continuing to use them. This is where you can put the custom access modifier, like this: public class Library { @Deprecated @Restricted(DoNotUse.class) public void foo() { ... } } This causes compilation to fail for new source files that try to call the foo method. But at the resulting class file still contains the method, so existing applications continue to work. As per the JVM spec, this contraint enforcement is strictly in the user land and thus voluntary, and at the runtime there's no check nor overhead. Or say you have a "public" class that's never intended to be used outside your library? Not a problem. @Restricted(NoExternalUse.class) public class FooBarImpl { ... } In the first version, I packaged the enforcer as a Maven mojo, but it should be trivial to write an Ant task or CLI. A real usability improvement is if this can be done as JSR-269 compatible annotation processor, but unfortunately the enforcer needs bytecode level access to the source files being compiled, and I don't think JSR-269 gives me ...


Date: April, 09 2010
Url: http://www.java.net/blog/kohsuke/archive/2010/04/09/potd-custom-access-modifier


Others News

©2002-2019Java-Virtual-Machine.net best website maker | free web design software | Bootstrap Templates | best web design software | bootstrap menu