Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  cast removal  (Read 1096 times)
0 Members and 1 Guest are viewing this topic.
Offline pepe

Junior Member




Nothing unreal exists


« Posted 2004-08-06 09:28:01 »

Let's say that i have a method that does like clone(), but implements the cloning itself. That method does not return an Object instance, but an instance of the class itself. I think it it to remove the need to cast, for two reasons: speed and typing reduced.
I don't believe that doing so is clever, as duplicating processes for a task is a Bad Thing©, and can introduce bugs directly and during updates, but this is an other story.
My question at the moment is:
is the cast point valid? Wouldn't hotspot remove the cast when returning from clone() in a case as the one  below?
1  
MyClass mc = (MyClass)myOtherClass.clone();


By the way... anyone ever benchmarked clone() opposed to hand done cloning?

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline pepe

Junior Member




Nothing unreal exists


« Reply #1 - Posted 2004-08-13 04:50:50 »

is there something wrong with the question, or simply nobody knows?

Home page: http://frederic.barachant.com
------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
Offline princec
« League of Dukes »

JGO Kernel


Medals: 197
Projects: 3


Eh? Who? What? ... Me?


« Reply #2 - Posted 2004-08-13 09:46:41 »

Maybe no-one knows. It's one of those things that's not likely to be a performance bottleneck anywhere I shouldn't think, either. I think that the cast is probably removable after the clone has been inlined.

Cas Smiley

Games published by our own members! Check 'em out!
Try the Free Demo of Revenge of the Titans
Offline crystalsquid

Junior Member




... Boing ...


« Reply #3 - Posted 2004-08-13 14:09:48 »

I don't think you even need the cast do you?

If MyOtherClass is derived from MyClass, then you should always be able to assign it to a base-class reference - at least you can in C++.

Casting the other way doen the inheritance tree is a different matter, and requires a cast and some care.

Speed wise I'm fairly certain that the cast would be more a compiler issue as opposed to generating any bytecodes from it - though I could be wrong on that too!  Wink

- Dom
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #4 - Posted 2004-08-13 14:30:21 »

Unfortunately clone() returns Object tho, so the cast is required.

Kev

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
mrbenebob (13 views)
2013-06-19 14:55:23

BrassApparatus (21 views)
2013-06-19 08:52:37

NegativeZero (24 views)
2013-06-19 03:31:52

NegativeZero (27 views)
2013-06-19 03:24:09

Jesse_Attard (31 views)
2013-06-18 22:03:02

HeroesGraveDev (67 views)
2013-06-15 23:35:23

Vermeer (66 views)
2013-06-14 20:08:06

davedes (68 views)
2013-06-14 16:03:55

alaslipknot (60 views)
2013-06-13 07:56:31

Roquen (84 views)
2013-06-12 04:12:32
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!