I was studying livewallpaper in this site. However something there is something that i dont understand.
Example in the code of the tutorial there a class named MyPoint
public class MyPoint {
String text;
private int x;
private int y;
public MyPoint(String text, int x, int y) {
this.text = text;
this.x = x;
this.y = y;
}
}
then after he created a MyWallpaperService class. Inside of that class there is a line of code like this
private List<MyPoint> circles;
private Paint paint = new Paint();
private int width;
int height;
private boolean visible = true;
private int maxNumber;
private boolean touchEnabled;
public MyWallpaperEngine() {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(MyWallpaperService.this);
maxNumber = Integer
.valueOf(prefs.getString("numberOfCircles", "4"));
touchEnabled = prefs.getBoolean("touch", false);
circles = new ArrayList<MyPoint>();
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(10f);
handler.post(drawRunner);
}
You can see the part of code has
private List<MyPoint> circles;
This is the part that i dont understand? What is happening in here? What will List<MyPoint> pass in the circles? Anyone knows what to call this? is this list reffering to a class? Cause im not sure on my title. Thank you..
States that circles is a
Listof typeMyPoint, (ie. it will hold objects of type MyPoint).Now in the above line you are assigning the ArrayList object of type MyPoint to the Object Reference Variable of type List.
This is called as Interface Polymorphism.
Listis an Interface, where asArrayLista Concrete Class which implements List.Eg: