inner-classes

Nested inner Activity class in android

孤者浪人 提交于 2019-12-19 16:55:16
问题 Is declaring a class that extends Activity inside another Activity class possible? If it is, how would I register that class in the manifest? Also, is that something that can be reasonably done or is it a bad idea? I was thinking of something like class ListClass extends ListActivity{ ... ArrayList items; class ItemClass extends Activity{ ... Item item; @Override onCreate(){ Integer pos = getIntent().getExtras().getInt("pos"); item = items.get(pos); } } @Override onItemClick(int position){

Nested inner Activity class in android

∥☆過路亽.° 提交于 2019-12-19 16:54:09
问题 Is declaring a class that extends Activity inside another Activity class possible? If it is, how would I register that class in the manifest? Also, is that something that can be reasonably done or is it a bad idea? I was thinking of something like class ListClass extends ListActivity{ ... ArrayList items; class ItemClass extends Activity{ ... Item item; @Override onCreate(){ Integer pos = getIntent().getExtras().getInt("pos"); item = items.get(pos); } } @Override onItemClick(int position){

Java compiler prohibit the creation in the inner class method with same name as in the outer class if the signatures are different

醉酒当歌 提交于 2019-12-19 12:45:13
问题 Why this code work: class Parent { private void methodA(String a){ System.out.println(a); } class Inner { void test(int a){ methodA("1"); } } } But This code not work(I just add method to inner class with same name and another signature): class Parent { private void methodA(String a){ System.out.println(a); } class Inner { private void methodA(int a){ System.out.println(a); } void test(int a){ methodA("1"); } } } I do not ask how to make it work. I want to mean why the second option doesn't

Does an inner class work as a composition relationship in java? [closed]

给你一囗甜甜゛ 提交于 2019-12-19 12:22:23
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . The inner class is always inside the outer class. If we removed the outer class, the inner class would also be destroyed. I'm not concerned about memory release, I am only thinking about the concept. And this is

Cannot declare Public static final String s = new String(“123”) inside an inner class

蹲街弑〆低调 提交于 2019-12-19 02:49:19
问题 I tried to declare a class as shown below class Outer{ private final class Inner{ public static final String s1 = new String("123"); public static final byte[] bytes = new byte[]{0x00, 0x01}; public static final String s2 = "123"; public static final byte byte1 = 0x02; } } In the above code s1 and bytes wont compile but s2 and byte1 compile. If I put the whole constant declaration in outer class it works fine. what am i missing. Any help? 回答1: Read Java Language Specification, 3rd ed, §8.1.3.

Is there a performance overhead to a private inner class in Java?

情到浓时终转凉″ 提交于 2019-12-18 13:09:26
问题 When I have inner classes with private methods or fields the compiler has to create synthetic package-protected accessor methods to allow the outer class to access those private elements (and vice-versa). To avoid that, I usually make all fields and methods and constructors package-protected instead of private. But how about the visibility of the class itself? Is there an overhead to private static class A { A(){} } versus static class A { A(){} } Note that the constructor is package

Example of inner classes used as an alternative to interfaces

血红的双手。 提交于 2019-12-18 12:32:47
问题 What I was told, which sparked my curiosity on this topic: Java gui classes can implement hundreds of Listeners and Callbacks and many books teach you to implement all these interfaces in your gui class. Alternatively, these aspects can be implemented in inner classes, so methods called by that listeners do not get mixed up. I'd like to know how to do this in ActionScript, which doesn't have inner classes, but has private classes. But, I don't think I fully realize what inner classes are

Example of inner classes used as an alternative to interfaces

▼魔方 西西 提交于 2019-12-18 12:32:05
问题 What I was told, which sparked my curiosity on this topic: Java gui classes can implement hundreds of Listeners and Callbacks and many books teach you to implement all these interfaces in your gui class. Alternatively, these aspects can be implemented in inner classes, so methods called by that listeners do not get mixed up. I'd like to know how to do this in ActionScript, which doesn't have inner classes, but has private classes. But, I don't think I fully realize what inner classes are

java inner/outer class questions about outer class private variables access

大憨熊 提交于 2019-12-18 11:47:50
问题 I have the following java class: class Outer { private Integer a; private Long b; class Inner { public void foo() { System.out.println("a and b are " + a + " " + b); } } } when I run javap on Outer and Outer$Inner, I get the following: C:\test>javap Outer Compiled from "Outer.java" class Outer extends java.lang.Object{ Outer(); static java.lang.Integer access$000(Outer); static java.lang.Long access$100(Outer); } C:\test>javap Outer$Inner Compiled from "Outer.java" class Outer$Inner extends

What are the uses of inner classes in Java? Are nested classes and inner classes the same? [duplicate]

寵の児 提交于 2019-12-18 11:09:48
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Java inner class and static nested class What are the uses of inner classes in Java? Are nested classes and inner classes the same? 回答1: No, they're not the same: an inner class is non- static . JLS 8.1.3 Inner Classes and Enclosing Instances An inner class is a nested class that is not explicitly or implicitly declared static. Consult also the following diagram from Joe Darcy: Joseph D. Darcy's Oracle Weblog -