first commit

This commit is contained in:
nestorpzu
2026-10-13 16:54:27 +02:00
commit eb3814173f
8 changed files with 152 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>aadd_comp02</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
+11
View File
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=25
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=25
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,70 @@
package org.palomafp.aadd.npz;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.palomafp.aadd.npz.model.Continente;
public class AppPrincipal {
public static void main (String[] args) {
AppPrincipal app = new AppPrincipal();
System.out.println("------------------- Probar introspección -------------------");
app.probarIntrospeccion();
System.out.println("\n------------------- Probar reflexión -------------------");
try {
app.probarReflexion();
} catch (Exception e) {
System.err.println("Ha fallado la reflexión: " + e);
}
}
// INTROSPECCIÓN = MIRAR cómo es una clase (no cambia nada)
private void probarIntrospeccion() {
Class<Continente> claseContinente = Continente.class;
System.out.println("Estoy mirando la clase: " + claseContinente .getSimpleName());
Field[] atributos = claseContinente .getDeclaredFields();
System.out.println("\nTiene " + atributos.length + " atributos:");
for (Field atributo : atributos) {
String nombre = atributo.getName();
String tipo = atributo.getType().getSimpleName();
System.out.println(" - " + nombre + " de tipo " + tipo);
}
Method[] metodos = claseContinente .getDeclaredMethods();
System.out.println("\nTiene " + metodos.length + " métodos:");
for (Method metodo : metodos) {
String nombre = metodo.getName();
String devuelve = metodo.getReturnType().getSimpleName();
System.out.println(" - " + nombre + "() devuelve " + devuelve);
}
}
// REFLEXIÓN = USAR una clase que solo conozco por su nombre en texto
private void probarReflexion() throws ClassNotFoundException, InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
NoSuchFieldException {
String nombreClase = "org.palomafp.aadd.npz.model.Continente";
Class<?> claseContinente = Class.forName(nombreClase);
System.out.println("Clase cargada: " + claseContinente .getName());
Object continente = claseContinente .getDeclaredConstructor().newInstance();
System.out.println("Objeto recién creado: " + continente);
Method setCodigo = claseContinente .getMethod("setCodigo", String.class);
setCodigo.invoke(continente, "01");
System.out.println("Con setCodigo(\"01\"): " + continente);
Field codigo = claseContinente .getDeclaredField("codigo");
codigo.setAccessible(true);
codigo.set(continente, "02");
System.out.println("Con el atributo = \"02\": " + continente);
}
}
@@ -0,0 +1,42 @@
package org.palomafp.aadd.npz.model;
import java.io.Serializable;
public class Continente implements Serializable {
private static final long serialVersionUID = 1L;
private String codigo;
private String nombre;
public Continente (){}
public Continente(String codigo, String nombre) {
super();
this.codigo = codigo;
this.nombre = nombre;
}
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
@Override
public String toString() {
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
}
}