https://github.com/dmlloyd/openjdk
In brief, write details of what the user is going to learn in a bullet list.
Choose one of the following options:
okay, on this occasion I will share a tutorial how to convert anonymous to inner refactoring.
Convert Anonymous to Inner refactoring is used to separate an anonymous inner class into an actual inner class. There are several varieties of anonymous inner classes:
For this section, we focus on the first type: unnamed subclasses.
Suppose you have the following code:
public class Item {
public void assemble() {
System.out.println("Item.assemble");
}
}
item name.factory name.public class Factory {
public void makeStandardItem(int type) {
if(type==0) {
Item myitem = new Item() {
public void assemble() {
System.out.println("anonymous Item.assemble");
}
};
myitem.assemble();
} else {
Item myitem = new Item();
myitem.assemble();
}
}
}
assemble().Factory class defines a variable myitem of type Item and instantiates an anonymous subclass of Item that overrides the assemble() method.Why would you bother using an anonymous inner class instead of a normal inner or outer class? In this example, if the one-off case where the anonymous inner class is used were the only area where it is needed, you might not want to create a separate class. However, if you find that you need the code in the anonymous subclass in multiple areas, you might want to convert it to an inner class.
Item myitem = new Item() {
public void assemble() {
System.out.println("anonymous Item.assemble");
}
};
NewClass , as shown in Figure 10-11.private class StrangeItem extends Item {
public void assemble() {
System.out.println("anonymous Item.assemble");
}
}
Factory class, since that is where the original anonymous inner class resides.public void makeStandardItem(int type) {
if(type==0) {
Item myitem = new StrangeItem();
myitem.assemble();
} else {
Item myitem = new Item();
myitem.assemble();
}
}
Factory class, and Convert Anonymous to Inner refactoring can help correct the situation.Include a list of related tutorials you have already shared on Utopian that make up a Course Curriculum, if applicable.
https://gist.github.com/andilapulga/f9071bd208acd94ce5f30918f42f7742