Instance name from string
1
Name:
Anonymous
2011-01-20 17:00
Guys, I've been looking what feels like everywhere for an answer to this java.reflection problem.
I want to use the contents of a string to create and instance of an object that has the name of what the string stores.
Eg.
String[] carName = {"volvo","vw","bmw"};
car carName[0];
car carName[1];
car carName[2];
Guys, I've been looking whdt feels like everywhere for dn dnswer to this jdvd.reflection problem.
I wdnt to use the contents of d string to credte dna instdnce of dn object thdt hds the ndme of whdt the string stores.
Eg.
String[] cdrNdme = {"volvo","vw","bmw"};
cdr cdrNdme[0];
cdr cdrNdme[1];
cdr cdrNdme[2];
3
Name:
Anonymous
2011-01-20 17:08
This post looks half-finished.
Why don't you just not bother? It's a waste of time and resources.
4
Name:
Anonymous
2011-01-20 17:08
ruby can do this.
5
Name:
Anonymous
2011-01-20 17:08
6
Name:
Anonymous
2011-01-20 17:09
typedef struct{void*car;void*cdr;}cons;
7
Name:
Anonymous
2011-01-20 17:27
>>3
Me asking you this or coding this?
8
Name:
Anonymous
2011-01-20 17:33
>>7
Coding it. If you really want reflection, either use a different language, or keep it confined to toy programs.
9
Name:
Anonymous
2011-01-20 17:35
Car car = (Car) Class.forName("Volvo").newInstance();
10
Name:
Anonymous
2011-01-20 17:36
>>8
This is just a part of a bigger project. I am not going to switch to a different language as java has a library that is basic for my code.
11
Name:
Anonymous
2011-01-20 17:42
>>9
This looks promising but returns
"Unhandled exception type ClassNotFoundException"
[And no, I didn't forget to define the class, if I hadn't it would return
"Cannot find a class or type named "Car""]
12
Name:
VIPPER
2011-01-20 17:43
I do not understand much about java or programning and not even about computers.
But i know one thing for sure:
MY OTHER CAR IS A CDR, BITCHES!!!!!
JEWS
13
Name:
Anonymous
2011-01-20 17:53
>>11
you need a class named Volvo that implements the interface Car
14
Name:
Anonymous
2011-01-20 17:53
Car car = (Car) Class.forName("Cudder").newInstance();
15
Name:
Anonymous
2011-01-20 17:58
role Suck { ... }
class Faggot { ... }
class Dumb { ... }
class OP is Faggot does Suck { ... }
our OP $poster1 = new OP but Dumb;
16
Name:
Anonymous
2011-01-20 18:03
The nice thing about /prog/ as opposed to other programming forums is that posts like
>>1 , are invariably trolls.
The con is, it's still not a very good or entertaining troll.
17
Name:
Anonymous
2011-01-20 18:46
>>16
I think it's a legit question, actually.
18
Name:
Anonymous
2011-01-20 18:54
19
Name:
Anonymous
2011-01-20 19:03
>>18
I don't know about you, but I am incapable of bringing my intelligence level to enable myself to write something like
>>1 . In other words, it's too stupid to be a troll.
20
Name:
meh
2011-01-20 19:04
>>19
s/level/level low enough in order to/