In Eclipse, how do I change the default modifiers in the class/type template?

Posted by gustafc on Stack Overflow See other posts from Stack Overflow or by gustafc
Published on 2009-10-23T08:02:44Z Indexed on 2010/04/04 16:23 UTC
Read the original article Hit count: 166

Filed under:
|
|
|

Eclipse's default template for new types (Window > Preferences > Code Style > Code Templates > New Java Files) looks like this:

${filecomment}
${package_declaration}

${typecomment}
${type_declaration}

Creating a new class, it'll look something like this:

package pkg;

import blah.blah;

public class FileName {
    // Class is accessible to everyone, and can be inherited 
}

Now, I'm fervent in my belief that access should be as restricted as possible, and inheritance should be forbidden unless explicitly permitted, so I'd like to change the ${type_declaration} to declare all classes as final rather than public:

package pkg;

import blah.blah;

final class FileName {
    // Class is only accessible in package, and can't be inherited
}

That seems easier said than done. The only thing I've found googling is a 2004 question on Eclipse's mailing list which was unanswered.

So, the question in short: How can I change the default class/type modifiers in Eclipse?

I'm using Eclipse Galileo (3.5) if that matters.

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse