Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 4

Emilio Cristobal Oviedo Castillo

A0144122149
Unidad 5. Genéricos en la programación

Aspecto 1

public class Par<F, S> {


private F e1;
private S e2;
public void setF(F e1) {
if (e1 == this.e2) {
System.out.println("elemento ya existe");
} else if (e1 != this.e2) {
this.e1 = e1;
}
}
public F getF() {
System.out.println(e1);
return this.e1;
}
public void setS(S e2) {
if (e2 == this.e1) {
System.out.println("elemento ya existe");
} else if (e2 != this.e1){
this.e2 = e2;
}
}
public S getS() {
System.out.println(e2);
return this.e2;
}
public static void main(String[] args) {
Par a = new Par();
a.setF(1);
a.getF();
a.setS(1);
a.getS();
a.setS(2);
a.getS();
}
}
-------------------< com.mycompany:LibroEjercicios >--------------------
Building LibroEjercicios 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:3.0.0:exec (default-cli) @ LibroEjercicios ---
1
elemento ya existe
null
2
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------

Aspecto 2

package POO;
public class EsIgualGene<T1, T2> {
T1 a;
T2 b;
public void setT1_T2(T1 a, T2 b) {
this.a = a;
this.b = b;
}
public boolean esIgual() {
boolean a;
if (this.a.equals(this.b)) {
System.out.println("verdadero");
return a = true;
}
System.out.println("falso");
return a = false;
}
public static void main(String[] args) {
EsIgualGene<Integer, Object> a = new EsIgualGene();
EsIgualGene<String, String> b = new EsIgualGene();
EsIgualGene<Object, Object> c = new EsIgualGene();
a.setT1_T2(1, 2);
a.esIgual();
a.setT1_T2(1, 1);
a.esIgual();
b.setT1_T2("P", "p");
b.esIgual();
b.setT1_T2("P", "P");
b.esIgual();
String b2 = "2";
Integer e = new Integer(b2);
String d = "2";
c.setT1_T2(e, d);
c.esIgual();
}
}
-------------------< com.mycompany:LibroEjercicios >--------------------
Building LibroEjercicios 1.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------

--- exec-maven-plugin:3.0.0:exec (default-cli) @ LibroEjercicios ---


falso
verdadero
falso
verdadero
falso
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Los resultados si corresponden al valor resultante según los argumentos recibidos

Aspecto 3

Repuesta = F.
Aspecto 4

Respuesta = B, E, D

You might also like