Objects creation

Hello folks!

Can anyone tell me the difference between creating objects like

Test7 t1=(Test7)Class.forName("Test7").newInstance();

Test7 t2=(Test7)Class.forName("Test7").newInstance();

and

Test7 t1 = new Test7();

Test7 t2 = new Test7();

When and where shall should i use them?

Thank you.

[342 byte] By [Zorama] at [2007-11-27 10:22:15]
# 1

The second way is the way you should use.

Eventually when you become smarter and you realize you need the first way, then you can use that. Not before.

-Kayaman-a at 2007-7-28 17:14:56 > top of Java-index,Java Essentials,Java Programming...
# 2

When Shall I use the first one?.

Can you tell me?

Zorama at 2007-7-28 17:14:56 > top of Java-index,Java Essentials,Java Programming...
# 3

> When Shall I use the first one?.

> Can you tell me?

You'lll know when you need it, trust me! I've seen too many people use the first idiom simply because they've just discovered it, to advise you using it. It's basically used when the types involved are not known at compile-time. But almost every beginner, when they discover the technique, uses it just for the sake of being clever, whereas the real cleverness comes in knowing that it's wasteful and inappropriate to use it in most cases

When you come across a situation where you cannot use the second idiom, it's time to look at the first. But not before then. You'll understand soon enough!

georgemca at 2007-7-28 17:14:56 > top of Java-index,Java Essentials,Java Programming...
# 4

Thank you georgemc,

Even I am just like that, I have just discovered it that I can use it, but dosen't know why i am using it. I hope I'll learnt it soon.

Zorama at 2007-7-28 17:14:56 > top of Java-index,Java Essentials,Java Programming...