Surround with instanceof

Hello,

Is there any way to surround cast with instance of or some similar technique
to avoid typing

if (o instanceof Docket) {
Docket d = (Docket)o;
....
}


2 comments
Comment actions Permalink

Alex Roytman wrote:

Hello,

Is there any way to surround cast with instance of or some similar technique
to avoid typing

if (o instanceof Docket) {
Docket d = (Docket)o;
....
}

Only two features I know of to do with instanceof is :
1) the live template 'inst' which will create the if clause with a
declared variable
2) an intention on an if (o instanceof Foo) { } clause which creates a
variable declaration for you within the braces.

Unless there's anything else I'm missing, sounds like you've landed on a
good idea for an intention for the case where you have an unchecked
cast, and want to surround it with a check.

N.

0
Comment actions Permalink

Alex Roytman wrote:

Hello,

Is there any way to surround cast with instance of or some similar technique
to avoid typing

if (o instanceof Docket) {
Docket d = (Docket)o;
....
}

Why not write your own template ?

0

Please sign in to leave a comment.