inner-classes

Access variable from inner class without making it final

℡╲_俬逩灬. 提交于 2019-12-04 22:48:41
how could i get this to work: public void onStart() { super.onStart(); int dayN = 0; int i = 0; String day = null; String addFach; String mo1 = null; String mo2 = null; String mo3 = null; String mo4 = null; String mo5 = null; String mo6 = null; String mo7 = null; String mo8 = null; String mo9 = null; String mo10 = null; String mo11 = null; String di1 = null; String di2 = null; String di3 = null; String di4 = null; String di5 = null; String di6 = null; String di7 = null; String di8 = null; String di9 = null; String di10 = null; String di11 = null; String mi1 = null; String mi2 = null; String

Inner static class inside inner class cannot be converted

别等时光非礼了梦想. 提交于 2019-12-04 22:00:16
问题 Inspired in this question: How to implements Iterable I decided to make a basic linked list implementation and implement an iterator in order to have a code like this: MyList<String> myList = new MyList<String>(); myList.add("hello"); myList.add("world"); for(String s : myList) { System.out.println(s); } The code wasn't hard to deal with, creating a class MyList<T> implements Iterable<T> with a private static class Node<T> and a private class MyListIterator<T> implements Iterator<T> , but

Is it possible to use parametrize generic inner classes?

本秂侑毒 提交于 2019-12-04 17:39:29
package generics; public class InnerClassGenerics{ class Innerclasss{ } public static void main(String[] args) { InnerClassGenerics icg=new InnerClassGenerics(); Innerclasss innerclass=icg.new Innerclasss(); } } Above code is possible and compiles fine!!! Why is the below code doesn't compile, and is it possible to parametrize inner classes? package generics; public class InnerClassGenerics<T>{ class Innerclasss<T>{ } public static void main(String[] args) { InnerClassGenerics<String> icg=new InnerClassGenerics<>(); Innerclasss<String> innerclass=new Innerclasss<>(); } } In the above code if

Referencing non-final variable: why does this code compile?

一曲冷凌霜 提交于 2019-12-04 15:15:34
问题 First off, I apologise if this is a duplicate question. I found many similar ones, but none that directly address my question. In preparation for an upcoming exam, I am doing a past paper. It has a question that gives a code snippet. We have to state if it compiles, and if not, write the line at which the first compiler error occurs and explain it. This is the snippet: public static void main(String[] args) { JFrame f = new JFrame("hi"); JTextField jtf = new JTextField(50); jtf

how to use nested class in another class in java?

眉间皱痕 提交于 2019-12-04 12:17:50
问题 I have some situation that I want to use inner class of another class in another class. like... public class ListData { public static class MyData { public String textSongName, textArtistName, textDuration, textDownloadPath, textSongSize, textAlbumName, textUrl; public boolean enable; public MyData(String songName, String artistName, String duration, String downloadPath, String songSize, String albumName, String url, boolean e) { textSongName = songName; textArtistName = artistName;

Inner Classes vs. Subclasses in Java

纵饮孤独 提交于 2019-12-04 09:40:26
Is there a situation where it is more beneficial to use an inner class over a subclass in Java (or vice-versa)? Based on my current understanding, inner classes have access to the fields and methods of the outer class. How is this any different from using inheritance? Subclasses generally have access to all the fields/methods labeled public and protected. Fields labeled private in the parent class can be accessed in the subclass using a getter method. Based off what I've seen thus far, when methods are labeled private, they're usually called in other methods of the class that are labeled

Why use method local abstract inner classes

坚强是说给别人听的谎言 提交于 2019-12-04 08:56:18
问题 One of the legal modifiers you can use with method local inner classes is abstract. For example: public class Outer { public void method(){ abstract class Inner{ } } } Is there any situation where you would actually use this? You have to know this for the SCJP exam. 回答1: The are some invalid assumptions in the original question. That something is legal/valid Java doesn't mean that it is something that you need to use, or need to know. I can't recall that the SCJP contains odd corner case

Java inner class with the same name as other top level class

跟風遠走 提交于 2019-12-04 08:47:29
I have question related to Java inner classes. Is there a way to access top level class A from top level class Main that define inner class A? Below is sample code demonstrating the problem: class A { // Outer Class A { System.out.println("A outer"); } } class B { // Outer Class B { System.out.println("B outer"); } } public class Main { class A { // Inner Class A { System.out.println("A inner"); } } public void newA() { class A { // Local Class A { System.out.println("A local"); } } new A(); } public static void main(String[] args) { new Main().newA(); // prints "A local" new Main().new A(); /

AspectJ Inner-Class Join points

流过昼夜 提交于 2019-12-04 08:40:57
I wonder is there a way to reach the code using aspect in "//do something" part? Thanks in advance. Turan. public class Test { private class InnerTest { public InnerTest() { JButton j = new JButton("button"); j.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //do something } }); } } } You can use the within or withincode pointcuts to match the containing class, and the cflow pointcut to match the execution of the addActionListener() method, then combine that with an execute pointcut to match the body of the actionPerformed() method. For example this

Must Inner classes have a reference to the enclosed class?

丶灬走出姿态 提交于 2019-12-04 07:00:46
问题 I have an inner class (non-static) which is using a reference to an enclosing class in its initialization. Will the inner class keep a reference to the enclosing class now? class Enclosing { class Inner { private final ABC innerField = outerField.computeSomething(); } private final XYZ outerField = something(); } UPDATE I am very much aware that one can reference the outer class with Enclosing.this . But, if the class doesn't use the reference, must the reference be there after compilation?