I am learning Java and found this article on stackoverflow.
So there are two classes:
public class Image {
...
public Image clone() {
Image clone = new Image(getMagicNumber(), getHeight(), getWidth(), getMax());
for (int i = 0; i < getHeight(); i++){
for (int j = 0; j < getWidth(); j++){
clone.setPixel(getPixel(i, j), i, j);
}
}
return clone;
}
}
And than there is this class:
public class Filter {
public Filter() {
}
public Image linearFilter(Image image, float[][] kernel) {
Image filtered = image.clone();
...
return filtered;
}
}
I am used to do X instancename = new X();
for creating an instance, where X
is the name of the class. Are there different ways for creating an instance? For example in the Filter
class: How is Image filtered = image.clone();
creating an instance? In order to create an instance I thought on both sides of the "equation" X has to be equal. What I mean by this: Image filtered = new Image();
. I don't understand how Image filtered = image.clone();
is creating a new instance. Can someone explain?