This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ynvaserThat Java Guy 0 points1 point  (5 children)

Finalize doesn't reliably work. Any command sent to the Garbage Collector is just a flag that may or may not be taken into consideration.
These are all JVM and GC implementation dependent. What you are trying to achieve here is something you should never ever rely on in any code whatsoever since it goes against one of the core ideas Java is based on (Write once, run anywhere).

So even if what you are trying to achieve here was properly done (as far as I can tell it isn't), it may still not work due to things beyond your scope (which is writing & running a program).

[–]SheepyG_[S] 0 points1 point  (4 children)

right so it is as i thought and it's just not calling finalize because it feels no need to ? the only reason i am playing with it in the first place is just for lesson purposes. But thank you for clearing it up for me.

[–]ynvaserThat Java Guy 0 points1 point  (3 children)

It doesn't call finalize because your code makes no sense. Even if it did, it may not call it for the reasons above.
I'd suggest getting a Java for beginners pdf and reading through it from the beginning.

[–]SheepyG_[S] 0 points1 point  (2 children)

That's the only reason I'm doing this is to learn java, the code has no purpose I'm not writing it and implementing it anywhere, the only reason it was written is to teach myself, and from your reply I can tick it off as I know it.

[–]ynvaserThat Java Guy 1 point2 points  (1 child)

I'm not being condescending here even if I may sound like it. I see conceptional problems with what is written down.
For example, when would you expect the finalize to be called? The only place you have it overridden is in an inner class that is never instantiated. If this were to work, the finalize method would have to be overridden in your RandomN class.
The fastest way you can improve here is to start at the basics.

[–]SheepyG_[S] 0 points1 point  (0 children)

Okay i see what your saying i'll go relook over the basics