Skip to content

Instantly share code, notes, and snippets.

@Burdzi0
Created May 20, 2017 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Burdzi0/cbd01e37ecc1326cf9b6e7728a487602 to your computer and use it in GitHub Desktop.
Save Burdzi0/cbd01e37ecc1326cf9b6e7728a487602 to your computer and use it in GitHub Desktop.
Example 1
package generics.ograniczony.argument.wieloznaczny;
/**
* Created by burdzi0 on 20.05.17.
*/
public class BoundedWildcard {
static <T extends TwoD> void showXY(Coords<T> c) {
System.out.println("Współrzędne X i Y: ");
for (int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x + " " + c.coords[i].y);
System.out.println();
}
}
static <T extends ThreeD> void showXYZ(Coords<T> c) {
System.out.println("Współrzędne X, Y i Z: ");
for (int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x + " " + c.coords[i].y + " " + c.coords[i].z);
System.out.println();
}
}
static <T extends FourD> void showXYZT(Coords<T> c) {
System.out.println("Współrzędne X, Y, Z i T: ");
for (int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x + " " + c.coords[i].y + " " + c.coords[i].z + " " + c.coords[i].t);
System.out.println();
}
}
public static void main(String[] args) {
TwoD td[] = {
new TwoD(2,3),
new TwoD(5,6),
new TwoD(18,-24),
new TwoD(-1,-23)
};
Coords<TwoD> tdlocs = new Coords<TwoD>(td);
System.out.println("Zawartość tdlocs.");
showXY(tdlocs);
//showXYZ(tdlocs);
//showXYZT(tdlocs);
FourD fd[] = {
new FourD(1,2,3,4),
new FourD(-3,-5,-7,-9),
new FourD(15,22,34,9),
new FourD(12,45,78,32)
};
Coords<FourD> fdlocs = new Coords<FourD>(fd);
System.out.println("Zawartość tdlocs.");
showXY(fdlocs);
showXYZ(fdlocs);
showXYZT(fdlocs);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment