About 2,640,000 results
Open links in new tab
  1. Access fields of an object passed as a parameter in Java?

    Jan 18, 2012 · Is it possible, in Java, to access fields of an object that is passed as a parameter in a method? Example code: void myMethod(ArrayList<Integer> list, MyClass object) { Integer myInt = object.x; // x is an Integer-type field in the object }

  2. Java reflection: how to get field value from an object, not …

    Apr 23, 2013 · If you know what class the field is on you can access it using reflection. This example (it's in Groovy but the method calls are identical) gets a Field object for the class Foo and gets its value for the object b. It shows that you don't have to care about the exact concrete class of the object, what matters is that you know the class the ...

  3. How to access and manipulate object properties using Java

    To access the properties of an object in Java, you can use methods, which are functions associated with the object. These methods are typically called "getter" methods, and they allow you to retrieve the values of the object's properties.

  4. Using Objects (The Java™ Tutorials > Learning the Java Language ...

    To access a field, you can use a named reference to an object, as in the previous examples, or you can use any expression that returns an object reference. Recall that the new operator returns a reference to an object. So you could use the value returned from new to access a …

  5. How to get keys and value from object in Java - Stack Overflow

    Feb 12, 2020 · I'm guessing you've come to Java from a language in which objects have loose types and are accessed approximately as key, value pairs which are often defined at run time. An example is json converting directly to JS objects with minimal translation.

  6. Get fields and values from an Object - Real's Java How-to - Real's HowTo

    We want to list the fields and the values of an instance. private ObjectUtils() {} public static Map<String, Object> getFieldNamesAndValues(final Object obj, boolean publicOnly) throws IllegalArgumentException,IllegalAccessException. Class<? extends Object> c1 = obj.getClass(); Map<String, Object> map = new HashMap<String, Object>();

  7. Passing and Returning Objects in Java - GeeksforGeeks

    Dec 27, 2021 · In java, a method can return any type of data, including objects. For example, in the following program, the incrByTen ( ) method returns an object in which the value of an (an integer variable) is ten greater than it is in the invoking object. Example.

  8. Objects (The Java™ Tutorials > Learning the Java Language > …

    A typical Java program creates many objects, which as you know, interact by invoking methods. Through these object interactions, a program can carry out various tasks, such as implementing a GUI, running an animation, or sending and receiving information over a network.

  9. Reading the Value of ‘private’ Fields from a Different Class in Java

    Jan 8, 2024 · Learn how to access the private fields of another class and read their values using the Java Reflection API.

  10. Accessing a static variable via an object reference in Java

    Feb 28, 2019 · Generally, public variables can be accessed by everybody, and private variables can only be accessed from within the current instance of the class. In your example you're allowed to access the x variable from the main method, because that method is …

  11. Some results have been removed
Refresh