anyone know any good java coding forums?

Started by venm11, June 25, 2003, 15:17:09

Previous topic - Next topic

venm11

I figured you guys might know of something.  I'm looking for web forums for java development on all kinds of topics - coding, apis, architecture, certifications and so forth.

Newsgroups and Sun JDC seem to have too many transients and too much noise... looking for something mid-sized with consistent, experienced people.

thanks folks.
Doug

princec

A fair few of us in here are experienced and consistent. Go right ahead and use the forums!

There's also javagaming.org which has a better signal-to-noise ratio than the general Java forums in Sun but tends to be populated with newbies and unfortunates attempting to write games in Java2D etc etc. I frequent the place myself.


Cas :)

venm11

Allright.  :)  Let me ask my current question--

Why are you not allowed to override static methods when subclassing?  What's their rationale for this rule?

princec

You can, but only using another static method.
The reason is that the statement:

obj.doSomething();

can not only refer to obj.doSomething() but also to MyObjectClass.doSomething() - you can imagine the fun and games if you were allowed to override a static doSomething() method with a nonstatic one.

So it's wisely disallowed.

Cas :)

venm11

I did an experiment and it does let you override a static method in a subclass;  it simply doesn't allow a name collision between static and instance methods, which is weird because their usage syntax isn't ambiguous; obj.doSomething() refers only to instance methods (and same for statics), right?

I guess the book people worded it incorrectly.

cfmdobbie

Not quite - obj.doSomething() is a perfectly valid way of accessing a static method on the class that is the type of the obj reference.  Phew!

The thing about statics is that they're not resolved at runtime, but at compile time.  While you *can* override a static method, it doesn't work in the same way as an overridden instance method.  Consider the following:

public class Foo
{
	public static String getName()
	{
		return "Foo" ;
	}

	public static void main(String[] args)
	{
		System.out.println(Foo.getName()) ; // "Foo"
		System.out.println(Baa.getName()) ; // "Baa"

		Foo f = new Foo() ;
		System.out.println(f.getName()) ; // "Foo"

		Baa b = new Baa() ;
		System.out.println(b.getName()) ; // "Baa"

		f = b ;
		System.out.println(f.getName()) ; // "Foo"
	}

	static class Baa extends Foo
	{
		public static String getName()
		{
			return "Baa" ;
		}
	}
}


I've added the actual output as a comment against each print.  Most people don't expect that last result!  While the object being accessed was of type Baa, the reference used was of type Foo, so "Foo" was printed.

Nasty, eh? :D
ellomynameis Charlie Dobbie.

princec

Although I've just got to add that it's considered bad style to call a static method from an instance and it might even be made illegal in a future version of the JDK.

Cas :)

Mojomonkey

Current compilers will even complain via warnings. Good example:

GL gl;
//...
gl.wglSwapIntervalEXT(1);


produces:

Quote
Warning         The static method wglSwapIntervalEXT(int) from the type GL should be accessed in a static way   jMonkeyEngine/jme/src/test/general/WaterRain.java   line 193
ever send a man to do a monkey's work.

Virum

www.digitaldesigners.org isn't a bad place.  We have a lots of good admins inlcuding *cough*me*cough*.  Anyway, we aren't swarming with newbie "do my homework for me" questions.............yet.  :)