About 268,000 results
Open links in new tab
  1. How do I pass a class as a parameter in Java? - Stack Overflow

    Oct 29, 2015 · Is there any way to pass class as a parameter in Java and fire some methods from that class? void main() { callClass(that.class) } void callClass(???? classObject) { classObject.somefunct...

  2. Pass a Class as a Parameter in Java - Baeldung

    Jun 20, 2024 · When working with Java programming, there are situations where we may need to pass a class as a parameter, enabling dynamic behavior and flexibility in our code. In this tutorial, we’ll delve into different approaches for achieving this in Java.

  3. Java Method Parameters - W3Schools

    Parameters act as variables inside the method. Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma. The following example has a method that takes a String called fname as parameter.

  4. How can I pass a Class as parameter and return a generic …

    Essentially you pass a TypeReference<T> instead of a Class<T>. The difference is that there is no List<String>.class, but you can make a TypeReference<List<String>>. So now we can make our container as follows (the following is adapted from Josh Bloch's original code): private Map<Type, Object> favorites = new HashMap<Type, Object>();

  5. java - Pass any Class as a parameter for a method - Stack Overflow

    Jan 24, 2019 · A Class instance – ClassA.class – is a singleton object that holds information about a class and can be passed as an argument to a method. An instance of a class – test – is an object. It's usually created using the new keyword.

  6. Java Pass Class Parameter: A Comprehensive Guide

    Pass class parameters is a fundamental skill in Java programming, especially for those looking to harness the full power of Object-Oriented Programming (OOP). Knowing how to structure and pass parameters can greatly enhance code readability and reusability.

  7. Passing and Returning Objects in Java - GeeksforGeeks

    Dec 27, 2021 · To do this, either we can use Object.clone () method or define a constructor that takes an object of its class as a parameter. Example. In java, a method can return any type of data, including objects.

  8. Generics in Java - GeeksforGeeks

    Apr 18, 2025 · Generics means parameterized types. The idea is to allow a type (like Integer, String, etc., or user-defined types) to be a parameter to methods, classes, and interfaces. Generics in Java allow us to create classes, interfaces, and methods where the type of the data is specified as a parameter.

  9. Parameterized Classes (and Interfaces) in Java - JMU

    Specializing a parameterized class; Specializing the parameters of a parameterized class; Type Inference: What can be and is inferred?

  10. Parameter Passing Techniques in Java with Examples

    Dec 6, 2022 · There are different ways in which parameter data can be passed into and out of methods and functions. Let us assume that a function B () is called from another function A (). In this case A is called the “caller function” and B is called the “called function or callee function”.

Refresh