Created
May 20, 2017 08:50
-
-
Save Burdzi0/cbd01e37ecc1326cf9b6e7728a487602 to your computer and use it in GitHub Desktop.
Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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