Quantcast
Channel: Static nested class in Java, why? - Stack Overflow
Browsing all 15 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Answer by Sahil Gupta for Static nested class in Java, why?

JVM knows no nested classes. Nesting is just syntactic sugar.Below images shows Java file:Below images show class files representation of the java file :Notice that 2 class files are generated, one for...

View Article



Answer by seenimurugan for Static nested class in Java, why?

Static inner class is used in the builder pattern. Static inner class can instantiate it's outer class which has only private constructor. You can not do the same with the inner class as you need to...

View Article

Answer by JenkinsY for Static nested class in Java, why?

Using a static nested class rather than non-static one may save spaces in some cases. For example: implementing a Comparator inside a class, say Student.public class Student { public static final...

View Article

Answer by Gaurav Tiwari for Static nested class in Java, why?

Adavantage of inner class--one time usesupports and improves encapsulationreadibility private field accessWithout existing of outer class inner class will not exist.class car{ class wheel{ }}There are...

View Article

Answer by user1923551 for Static nested class in Java, why?

static nested class is just like any other outer class, as it doesn't have access to outer class members.Just for packaging convenience we can club static nested classes into one outer class for...

View Article


Answer by John29 for Static nested class in Java, why?

From http://docs.oracle.com/javase/tutorial/java/javaOO/whentouse.html:Use a non-static nested class (or inner class) if you require access to an enclosing instance's non-public fields and methods. Use...

View Article

Answer by The Gun for Static nested class in Java, why?

Non static inner classes can result in memory leaks while static inner class will protect against them. If the outer class holds considerable data, it can lower the performance of the application.

View Article

Answer by Leigh for Static nested class in Java, why?

There are non-obvious memory retention issues to take into account here. Since a non-static inner class maintains an implicit reference to it's 'outer' class, if an instance of the inner class is...

View Article


Answer by Vinze for Static nested class in Java, why?

Simple example : package test;public class UpperClass {public static class StaticInnerClass {}public class InnerClass {}public static void main(String[] args) { // works StaticInnerClass stat = new...

View Article


Answer by DavidLG for Static nested class in Java, why?

Well, for one thing, non-static inner classes have an extra, hidden field that points to the instance of the outer class. So if the Entry class weren't static, then besides having access that it...

View Article

Answer by matt b for Static nested class in Java, why?

The Sun page you link to has some key differences between the two:A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the...

View Article

Answer by Juri Pakaste for Static nested class in Java, why?

I don't know about performance difference, but as you say, static nested class is not a part of an instance of the enclosing class. Seems just simpler to create a static nested class unless you really...

View Article

Answer by Mark Renouf for Static nested class in Java, why?

One of the reasons for static vs. normal have to do with classloading. You cannot instantiate an inner class in the constructor of it's parent.PS: I've always understood 'nested' and 'inner' to be...

View Article


Answer by Jon Skeet for Static nested class in Java, why?

To my mind, the question ought to be the other way round whenever you see an inner class - does it really need to be an inner class, with the extra complexity and the implicit (rather than explicit and...

View Article

Static nested class in Java, why?

I was looking at the Java code for LinkedList and noticed that it made use of a static nested class, Entry.public class LinkedList<E> ... {... private static class Entry<E> { ... }}What is...

View Article

Browsing all 15 articles
Browse latest View live




Latest Images