Questions tagged [dynamic-class-creation]

Some Object Oriented programming languages allow creating new classes (types) in run-time (as compared to classes defined in the source code and created in compilation time)

Some examples of creating types in run-time:
C#
C++
Java
Python

78 questions
3
votes
2 answers

dynamic creating class in C#

I want to know if there is a way to generate the class dynamically at runtime. I want to use it in Entity framework code first. Consider if I have 100 tables(or connect to unknown database) I will have to create model/POCO for each table in EF Code…
2
votes
1 answer

Targeting Dynamic Div

I am having trouble targeting a specific div on click, currently when I click "currentTarget.id" the function returns all of the div objects within my JSON file instead of the one that was clicked. I have tried a bunch of different solutions from…
2
votes
0 answers

Dynamic class generation at runtime in the JVM

I need to take input at runtime and create a new class with it, and load it into the JVM to run. Although this can quickly become an abstract question with minimal concrete answers, and therefore be marked "Not appropriate for stackoverflow", I…
Nate Schreiner
  • 759
  • 2
  • 7
  • 15
2
votes
1 answer

exec vs type when dynamically creating class in Python

I have a luigi pipeline. We have a lot and lots of external files that change with a regular basis, and we want to be able to build the pipeline from metadata. I create classes dynamically, and have found two ways to do it: Using…
hirolau
  • 13,451
  • 8
  • 35
  • 47
2
votes
3 answers

CSharp: How do I dynamically call a class(with constructor) and it's methods?

I've been reading examples of Reflection for two days and I can't quite seem to piece together everything to fit what I need. In fact I thought I was using reflection, until I noticed my "using System.Reflection" was grayed out. :-) I have an xml…
Jason
  • 463
  • 1
  • 11
  • 25
2
votes
2 answers

How to Create Java class/es files dynamically?

I need a way to run a java method for ex. createModule("Login") and as an output to have: New folder named mod_login Inside on mod_login java classes files created from a template If the template is class Name extends Blah implement Blah { …
Jbwz
  • 185
  • 15
2
votes
4 answers

What frameworks/languages support run-time class creation?

I'm trying to put together a list of frameworks/languages support run-time class creation. For example in .NET you can use the System.Reflection.Emit library to emit new classes at run time. If you could mention other frameworks/languages that…
2
votes
1 answer

super class not assignable to class implemented during runtime by asm

I have a java class that consist of an inner interface, and plan to implement the implementation class during runtime with asm bytecode injection. package my.example; public class X{ public static interface XInt{ public void getX(); …
2
votes
3 answers

Using Java Reflection to determine which class to instantiate

There is a Message superclass and there are various Message subclasses like WeddingMessage, GreetingMessage, FarewellMessage, Birthday Message. The Message superclass has a constructor: public Message(String messageType){ this.messageType =…
2
votes
2 answers

How can I test a .class file was created?

I want to unit test my code which will have to create a .java file compile it and then the corresponding .class file should be created. How can I create the test to see if the ".class" file is created? I have added test already for its existence,…
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
1
vote
2 answers

Class creation using eval of dynamically-created string of method def's

I have a strange situation where the code: c = Class.new { eval parser } ... works in IRB (ruby 1.9.3) but not in code. I've tried it with and without 'class Foo' wrapping my methods. This is frustrating, to say the least. I can copy the string…
1
vote
0 answers

How to generate a POJO class(kotlin/java) programmatically with variables based on REST API response?

I need to generate a data class at run time based on my REST API response with the given class name , and need to access it .Here is the sample json response and expected sample data class . 1) Sample JSON RESPONSE "total": 123, "currentCount":…
1
vote
2 answers

Unable to use dynamic classes with concurrent.futures.ProcessPoolExecutor

In the code below, I am dynamically creating an object of the class inside the _py attribute by using the generate_object method. The code works perfectly if I am not using a concurrent approach. However, if I use concurrency from…
1
vote
0 answers

How do I assign integer or string values to dynamic classes in python

I have a code in python which looks something like this: def Make_My_Class(): My_Class = type("My_Class", (object, ), { "__init__": Callinit, "My_Funct": Call_My_Funct, }) def Callinit(self): self.value=0 def…
nonsqu
  • 25
  • 2
1
vote
1 answer

How to supply runtime generated groovy classes to Spring Boot context configuration process

I am generating classes from Groovy source and store them in GroovyClassLoader. These classes have @Configuration annotation. They are in package a.b.c.d.e. I want them to configure my spring context. I set thread context class loader to be this…
igobivo
  • 433
  • 1
  • 4
  • 17