I actually have this code template set up for my Eclipse. Here's how you can configure it.
Open the Preferences
dialog by going to Windows > Preferences
and then navigate to Java > Editor > Templates
. Click on New...
here to create a new Code Template as shown below.
Now, within the Java file editor, select the Object you want to type cast and hit Ctrl + Space
.
Invoke the code template and you'll get something like
[type] [new_name] = ([type]) new ArrayList<String>();
where the []
indicate that type can be specified using auto-complete.
There's also a default cast
template available which can be invoked by typing cast
and then hitting Ctrl + Space
. The difference is that it doesn't support selections but lets you specify the target object through auto-complete. I find both the variants useful.
[type] [new_name] = ([type]) [name];