Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
How to add properties functions to objects from another class in Java?

In Javascript we can define an object like this 👇

let obj={
    property1:67,
    func1: function (){
        //Some code
    }
}

Now if we want add a new property to obj I can just add a new property like this

obj.property2=733; //some value or function

Now I want to do the same thing in Java also.

I have a class Test 👇

public class Test{
    int property1=67;
    public void func1(){
        //Some code
    }
}

Now is it possible to do like the same thing like statement #2 in Java also?

Edit: From the answers I got to know that we can use a Map for properties. Now I want to know for methods. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So I did a research and as I can see this is not simple.

In java you can not do that, actually, you can if you provide your own custom class loading, which is really a bad idea because then even if you change the class you want you must reload all classes that interact with this class.

Check this article to understand more about class loaders.

Of course, there are some other ways as:

  • ASM an all-purpose Java bytecode manipulation and analysis framework.

  • Javassist a library for editing bytecodes in Java

  • AspectJ aspect-oriented extension to the Java, mostly used to clean modularization of crosscutting concerns

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda