From: Doni Pracner Date: Wed, 29 Apr 2015 11:26:15 +0000 (+0200) Subject: Jednostavan primer za opsti tip (generic) u programskom jeziku Java X-Git-Url: https://svarog.pmf.uns.ac.rs/gitweb/?a=commitdiff_plain;h=43fcd4a31c0612b4134bc816e5284c4f904cf0d5;p=spa1-materijali.git Jednostavan primer za opsti tip (generic) u programskom jeziku Java --- diff --git a/kodovi/skup/OpstiTipoviPrimeri.java b/kodovi/skup/OpstiTipoviPrimeri.java new file mode 100644 index 0000000..26e96d3 --- /dev/null +++ b/kodovi/skup/OpstiTipoviPrimeri.java @@ -0,0 +1,32 @@ +class Cuvar { + T info; + + public String toString(){ + return "Cuvam:" + info; + } + + public Cuvar(){ + info = null; + } + + public Cuvar(T podatak){ + this.info = podatak; + } +} + + +public class OpstiTipoviPrimeri { + + public static void main(String[] args) { + Cuvar st = new Cuvar(); + st.info = "neki string"; + System.out.println(st); + + Cuvar broj = new Cuvar(); + broj.info = 5; + System.out.println(broj); + + Cuvar realan = new Cuvar(5.0); + System.out.println(realan); + } +}