Reputation: 2973
class Demo{
static void Test(){
System.out.println("hello");
}
}
Is there any keyboard shortcut in eclipse for creating an object of a class declared above .
e.g after writing Demo followed by that shortcut , it should write as below
Demo objname = new Demo();
Upvotes: 1
Views: 2483
Reputation: 1
Alt + Shift + L is a handy keyboard shortcut in Eclipse for creating an object of a class.
It’s a quick way to generate an instance of a class without having to manually type out the new keyword and the class name.
For those who might not be familiar with it, here’s how you can use it:
Navigate to the Class: First, make sure you’re in the right place in your code (e.g., within a method where you want to create the object).
Type the Shortcut: Press Alt + Shift + L simultaneously.
Eclipse will automatically insert the necessary code to create an object of the class at the cursor position.
Fill in the Details: If the class has constructors with parameters, Eclipse will prompt you to provide the required arguments. You can select the appropriate constructor and fill in the values.
Upvotes: 0
Reputation: 4855
I don't think you can do exactly that, but this is close:
Type new Demo()
then ctrl-2 L
(Quick Assist - Assign to local variable).
Eclipse will change the line to Demo demo = new Demo();
and give you a chance to rename the variable.
Upvotes: 3