About 1,740,000 results
Open links in new tab
  1. What is the exact meaning of instantiate in Java

    Jun 1, 2017 · Instantiate in Java means to call a constructor of a Class which creates an an instance or object, of the type of that Class. Instantiation allocates the initial memory for the object and returns a reference. An instance is required by non-static methods as they may operate on the non-static fields created by the constructor.

  2. How to instantiate an object in java? - Stack Overflow

    Aug 1, 2013 · And in JAVA you don't have to instantiate methods. Objects are instances of class. A method is just a behavior which this class has. For your requirement, you don't need to explicitly instantiate anything as when you run the compiled code JAVA automatically creates an instance of your class and looks for main() method in it to execute.

  3. java - How to directly initialize a HashMap (in a literal way)? - Stack ...

    Java 9 added a series of Map.of static methods to do just what you want: Instantiate an immutable Map using literal syntax. The map (a collection of entries) is immutable, so you cannot add or remove entries after instantiating. Also, the key and the …

  4. How do I declare and initialize an array in Java? - Stack Overflow

    Jul 29, 2009 · Number[] numArray = {1,2,3,4}; // java.lang.Number numArray[0] = new Float(1.5f); // java.lang.Float numArray[1] = new Integer(1); // java.lang.Integer // You can store a subclass object in an array that is declared // to be of the type of its superclass. // Here 'Number' is the superclass for both Float and Integer.

  5. java - Difference between initializing a class and instantiating an ...

    Feb 25, 2013 · When a Java class is "loaded" into the JVM the class representation must be initialized in several ways. The class's "constant pool" is expanded into a runtime structure and some values in it are initialized. The superclass of the class is located (via the constant pool) and attributes of it extracted.

  6. Instantiating generics type in java - Stack Overflow

    Apr 11, 2020 · Second, you can't instantiate T because Java implements generics with Type Erasure. Almost all the generic information is erased at compile time. Basically, you can't do this: T member = new T(); Here's a nice tutorial on generics.

  7. java - Instantiate enum class - Stack Overflow

    May 31, 2013 · Here I need to specifying Sample.READ to pass it as parameter. Instead if we want to instantiate the enum class and pass it as parameter what we need to do? What would "instantiate the enum class" even mean? The point of an enum is that there are a fixed set of values - you can't create more later. If you want to do so, you shouldn't be using ...

  8. java - How to initialize HashSet values by construction ... - Stack ...

    Jan 11, 2010 · Here the collector would actually return the unmodifiable set introduced in Java 9 as evident from the statement set -> (Set<T>)Set.of(set.toArray()) in the source code. One point to note is that the method Collections.unmodifiableSet() returns an unmodifiable view of the specified set (as per documentation).

  9. Instantiating interfaces in Java - Stack Overflow

    May 25, 2013 · So don't be fooled by any attempts to instantiate an interface except in the case of an anonymous inner class. The following is not legal: Runnable r = new Runnable(); // can't instantiate interface whereas the following is legal, because it's instantiating an implementer of the Runnable interface(an anonymous implementation class):

  10. Java - How to create new Entry (key, value) - Stack Overflow

    Jun 24, 2010 · I can't use Map.Entry itself because apparently it's a read-only object that I can't instantiate new instanceof. That's not entirely accurate. The reason why you can't instantiate it directly (i.e. with new) is because it's an interface Map.Entry.

Refresh