Questions tagged [instantiation]

Instantiation is the process of creating objects from a class in most object oriented and object based languages. In the C++ language, instantiation is the process of creating a class or function from a class template or function template.

2609 questions
25
votes
3 answers

Scala 2.10, its impact on JSON libraries and case class validation/creation

In Scala 2.10 apparently we're getting improved reflection. How will this impact lift-json, jerkson, sjson and friends? Furthermore, can we expect in the not too distant future a built-in JSON language feature a la Groovy's excellent GSON in…
virtualeyes
  • 11,147
  • 6
  • 56
  • 91
24
votes
2 answers

PMD: Avoid instantiating new objects inside loops

I've got an issue with the PMD rule Avoid instantiating new objects inside loops. Here is some example code: import java.awt.Dimension; public class PMDDemo { public static void main(final String[] args) { final Dimension[] arr = new…
brimborium
  • 9,362
  • 9
  • 48
  • 76
24
votes
4 answers

Profiling template metaprogram compilation time

I'm working on a C++ project with extensive compile-time computations. Long compilation time is slowing us down. How might I find out the slowest parts of our template meta-programs so I can optimize them? (When we have slow runtime computations,…
idupree
  • 730
  • 5
  • 16
23
votes
4 answers

How to instantiate a class in Objective-C that don't inherit from NSObject

Given this: Person.h: @interface Person { } - (void) sayHello; @end Person.m: #import "Person.h" @implementation Person - (void)sayHello { printf("%s", "Steve"); } @end How do you instantiate the Person? I tried this: Person *p =…
Hao
  • 8,047
  • 18
  • 63
  • 92
23
votes
2 answers

How to instantiate an object in TypeScript by specifying each property and its value?

Here's a snippet in which I instantiate a new content object in my service: const newContent = new Content( result.obj.name result.obj.user.firstName, result.obj._id, result.obj.user._id, ); The problem is that this way of…
YSA
  • 799
  • 1
  • 12
  • 30
23
votes
5 answers

Avoid instantiating a class in java

Recently I've faced a question : How to avoid instantiating a Java class? However, I answered by saying: If you don't want to instantiate a class, use "abstract" modifier. Ex: javax.servlet.HttpServlet, is declared as abstract(though none of its…
jai
  • 21,519
  • 31
  • 89
  • 120
22
votes
2 answers

Swift: Creating an Array with a Default Value of distinct object instances

I noticed a bit weird (and dangerous IMHO) behavoir in Creating an Array with a Default Value. As stated in Swift 2.1: Collection Types Swift’s Array type also provides an initializer for creating an array of a certain size with all of its values…
Franco Rondini
  • 10,841
  • 8
  • 51
  • 77
21
votes
2 answers

Inline object instantiation and transformation in Java

I have come to Java from Visual Basic, and seem to think I have been, in many ways, spoiled :p Is there a way to instantiate an object and modify it inline? Something like: JFrame aFrame = new JFrame(); aFrame.add(new JPanel() {.setSize(100,100)…
GCon
  • 1,397
  • 3
  • 16
  • 33
21
votes
2 answers

Why do Object.create() and new Object() evaluate to different prototypes?

Why do these 2 implementations behave differently? What exactly sets them apart when it comes to evaluating their prototypes? Creating an object with the prototype specified: function Foo() {} // creates an object with a specified prototype …
shmuli
  • 5,086
  • 4
  • 32
  • 64
21
votes
2 answers

How is a template instantiated?

It's an exercise from C++ Primer 5th Edition: Exercise 16.27: For each labeled statement explain what, if any, instantiations happen. If a template is instantiated, explain why; if not, explain why not. P.677 template class Stack…
Yue Wang
  • 1,710
  • 3
  • 18
  • 43
21
votes
2 answers

Exporting STL class from DLL - why is there no warning from the return type?

My question is related to exporting a C++ class with STL inside. For example: class __declspec(dllexport) Hello { std::string name; public: std::string& getName(); void setName(const std::string& name); } Various articles…
xpirle
  • 311
  • 2
  • 6
21
votes
5 answers

Instantiating C++ lambda by its type

I want a way to make functor from function. Now I trying to wrap function call by lambda function and instantiate it later. But compiler says than lambda constructor is deleted. So is there any way to compile this code ? Or maybe another way for…
andigor
  • 722
  • 6
  • 17
20
votes
3 answers

Class 'Room' is abstract; cannot be instantiated

I have an abstract class Room which has subclasses Family and Standard. I have created room = new ArrayList(); within a Hostel class and a method to add a room to the ArrayList; public String addRoom(String roomNumber, boolean ensuite) { …
Darren Burgess
  • 4,200
  • 6
  • 27
  • 43
20
votes
5 answers

Instantiating object from inside the main of that class in Java

I was looking through my OOP class documentation and I found this example: class Student { private String name; public int averageGrade; public Student(String n, int avg) { name = n; averageGrade = avg; } …
Mihai Neacsu
  • 2,045
  • 5
  • 23
  • 37
20
votes
5 answers

Composing a Controller class with Dependency Injection in PHP

How to solve the problem of composing a Controller class in PHP, which should be: easily testable by employing Dependency Injection, provide shared objects for end programmer provide a way to load new user libraries Look down, for controller…