inner-classes

python: determine if a class is nested

折月煮酒 提交于 2019-12-07 03:41:43
问题 Suppose you have a python method that gets a type as parameter; is it possible to determine if the given type is a nested class? E.g. in this example: def show_type_info(t): print t.__name__ # print outer class name (if any) ... class SomeClass: pass class OuterClass: class InnerClass: pass show_type_info(SomeClass) show_type_info(OuterClass.InnerClass) I would like the call to show_type_info(OuterClass.InnerClass) to show also that InnerClass is defined inside OuterClass. 回答1: AFAIK, given a

Casting to an inner class with generics

时光毁灭记忆、已成空白 提交于 2019-12-07 03:32:02
问题 Consider the following code: public class Outer<T> { public class Inner{ } public static <T> Outer<T>.Inner get(){ Object o = new Object(); return (Outer<T>.Inner)o; } public static void main(String[] args) throws Exception { Outer.<String>get(); } } This code compiles successfully in Eclipse, but fails to compile in javac : Outer.java:10: ')' expected return (Outer<T>.Inner)o; ^ Outer.java:10: ';' expected return (Outer<T>.Inner)o; ^ Outer.java:10: illegal start of expression return (Outer<T

Instantiating an inner class (Preference) in xml file

十年热恋 提交于 2019-12-06 21:19:12
问题 When you want to access a custom view in some layout.xml file, you have two options: The view is in it's own class. Then you do <package.name.MyView android:layout_width= ... /> The view is an inner class: <view class="package.name.OuterClass$MyView" android:layout_width= ... /> Now I want to do the same thing inside a <PreferenceScreen> . The first way works well, but I would like to put all the custom Preference classes together in my PreferenceActivity. I tried <Preference class="package

Are non-static inner class objects garbage collected after they are no longer referenced?

醉酒当歌 提交于 2019-12-06 17:28:48
问题 I have a single spring bean similar to the following: public class MyServiceImpl { private MyDAO myDAO; public class MyInnerClass implements SomeInterface<MyInnerClass> { @Override public MyInnerClass loadFreshObject(final String key) { return myDAO.load(key); } } } Instances of MyInnerClass are being created in code outside of the spring bean but no reference to those instances are being kept. Assuming I have no control over the use of these public non-static inner classes (I know ideally

Access variable from inner class without making it final

孤者浪人 提交于 2019-12-06 16:33:50
问题 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;

Local variables referred from inner class must be final or effectively final

[亡魂溺海] 提交于 2019-12-06 14:54:51
问题 Please have a look at the below code private void displayInitialRevenue_Method() { //Get the dates from the combo String selectedCouple = revenueYearCombo.getSelectedItem().toString(); if (selectedCouple.equals("Select Year")) { return; } String[] split = selectedCouple.split("/"); //Related to DB double totalAmount = 0.0; //Get data from the database dbConnector = new DBHandler(); dbConnector.makeConnection(); DefaultTableModel model = (DefaultTableModel) initialRevenueTable.getModel();

How the private properties of inner class are accessed from outside class?

冷暖自知 提交于 2019-12-06 14:17:45
问题 I have read this concept in respect to static inner class : ViewHolder declared as inner class inside the adapter of ListView to enhance the performance of getView(). Consider the below class public class OuterClass{ public class InnerClass{ private int privateProperty= -2; } public static void main(String[] args) { OuterClass oc = new OuterClass(); InnerClass ic = oc.new InnerClass(); ic.privateProperty = -98; } } If inner class contains private properties and an object of inner class is

what is the difference between an inner class and a local inner class in java?

谁都会走 提交于 2019-12-06 11:04:20
问题 If a class is a local inner class, does this mean that it is inside a method of another class or does it mean that it is just defined in another method somewhere. For example, in the code below, is the MenuListener considered an inner local class? import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MenuDemo extends JFrame{ private Container c; private ImageIcon[] images = new ImageIcon[5]; private JLabel picture; private JPanel mainPanel; private JMenuBar menuBar;

Is it possible to use parametrize generic inner classes?

做~自己de王妃 提交于 2019-12-06 10:29:35
问题 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

Scala: Can't get outer class members from inner class reference

自古美人都是妖i 提交于 2019-12-06 07:01:37
I can't seem to get the outer class members from an inner class reference: class Outer(st: Int) { val valOut = st def f = 4 class Inner { val x = 5 } } object myObj { val myOut = new Outer(8) val myIn = new myOut.Inner val myVal: Int = myIn.valOut//value f is not a member of ... myOut.Inner val x = myIn.f//value valOut is not a member of ... myOut.Inner } I've tried this inside packages and in the eclipse worksheet neither works. I'm using Scala 2.10.0RC1 in eclipse 3.7.2 with Scala plug-in 2.1.0M2 I don't know why you expect this to compile. After all, Inner does not have those members, only