inner-classes

Are anonymous classes a subset of inner class?

拜拜、爱过 提交于 2019-12-04 06:59:58
问题 It might sound like a dumb question, but all anonymous classes must be defined and instantiated within an existing class; therefore, they must be inner classes at the same time. 回答1: This is quite true. Your anonymus class could not be implemented outside of other classes, as a seperate class, because as it is anonymus you would not be even able to refer to it in any way. Additional information: From JLS: An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.1

Android - Implementing Parcelable Inner Class

天大地大妈咪最大 提交于 2019-12-04 06:34:58
问题 I know how to implement a simple Parcelable class with public variables but the class below is somewhat more complex. How can I implement the Parcelable interface given that this class has an inner class and ListEntity? I'm not even sure how to begin. Any detailed information on how to do this would be greatly appreciated. import android.os.Parcel; import android.os.Parcelable; import java.util.List; public class ResponsePlaceSearch implements Parcelable { // *** Parcelable methods are shown

Scala abstract types in classes within objects

て烟熏妆下的殇ゞ 提交于 2019-12-04 06:24:00
问题 If I do this: object Parent { class Inner extends Testable { type Self <: Inner } def inner = new Inner() } object Child { class Inner extends Parent.Inner { type Self <: Inner } def inner = new Inner() } trait Testable { type Self def test[T <: Self] = {} } object Main { // this works val p: Parent.Inner = Child.inner // this doesn't val h = Parent.inner h.test[Child.Inner] } I get this error: error: type arguments [Child.Inner] do not conform to method test's type parameter bounds [T <:

How to use java proxy in scala

时间秒杀一切 提交于 2019-12-04 04:29:34
I have an interface as Iface that has two methods written in java. That interface is an inner interface of Zzz class. I have written the invocation handler in scala. Then I tried to create a new proxy instance in scala like below. val handler = new ProxyInvocationHandler // this handler implements //InvocationHandler interface val impl = Proxy.newProxyInstance( Class.forName(classOf[Iface].getName).getClassLoader(), Class.forName(classOf[Iface].getName).getClasses, handler ).asInstanceOf[Iface] But here the compiler says that $Proxy0 cannot be cast to xxx.yyy.Zzz$Iface How can I do this with

Defining inner class outside java file

╄→гoц情女王★ 提交于 2019-12-04 03:25:55
问题 I want to create a class, ClassB , as inner class of ClassA , but I want to write down outside ClassA.java file. How can I do this? It will be a lot of inner class, and ClassA.java file will be enormous . UPDATE What I really want to do is define ten classes that they will be only accessible by one class. All of them are defined inside the same package. Thanks. 回答1: Put all your classes in a package and define the classes to be package private. package com.example.here class Hello{ //... }

Scala closures compared to Java innerclasses -> final VS var

南楼画角 提交于 2019-12-04 03:12:51
问题 I've first asked this question about the use of final with anonymous inner classes in Java: Why do we use final keyword with anonymous inner classes? I'm actually reading the Scala book of Martin Odersky. It seems Scala simplifies a lot of Java code, but for Scala closures I could notice a significant difference. While in Java we "simulate" closures with an anonymous inner class, capturing a final variable (which will be copied to live on the heap instead of the stack) , it seems in Scala we

Error when defining inner classes in a Test class in JUnit

◇◆丶佛笑我妖孽 提交于 2019-12-04 02:45:59
I'm having some problems when defining inner classes in a Test class inherited from TestCase, for JUnit 3. Scenario is like following: Foo.java public class Foo { public void method() { ... } } FooTest.java public class FooTest extends TestCase { public class Bar extends Foo { public void method() { ... } } public void testMethod() { ... } } Now, if I run this from Eclipse, the tests run ok, but if I try to run from an Ant task it fails: [junit] junit.framework.AssertionFailedError: Class Foo$Bar has no public constructor TestCase(String name) or TestCase() Bar is NOT a Test class, it's just a

Inner Class in Java

北城余情 提交于 2019-12-04 02:36:53
I was reading about Inner class in Learning Java. I found this code class Animal{ class Brain{ } } After compiling, javap 'Animal$Brain' gives output as Compiled from "Animal.java"class Animal$Brain { final Animal this$0; Animal$Brain(Animal); } which explains how the inner class gets the reference to its enclosing instance in the inner class constructor. But when I define the inner class as private like this class Animal{ private class Brain{ } } then after compiling, javap 'Animal$Brain' gives the output as Compiled from "Animal.java" class Animal$Brain { final Animal this$0; } So why is the

What is a static nested class? [duplicate]

本秂侑毒 提交于 2019-12-04 02:29:34
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Java: Static vs non static inner class What is a static nested class? What is the difference between static and non-static nested classes? 回答1: A static inner class is a class nested inside another class that has the static modifier. It's pretty much identical to a top-level class, except it has access to the private members of the class it's defined inside of. class Outer { private static int x; static class

When extending a trait within a trait, what does 'super' refer to?

只愿长相守 提交于 2019-12-03 23:28:08
I want to to extend a trait within a trait, like this: trait NodeTypes { trait Node { def allNodesHaveThis: Int } } trait ScrumptiousTypes extends NodeTypes { trait Node extends super.Node { def scrumptiousness: Int } } trait YummyTypes extends NodeTypes { trait Node extends super.Node { def yumminess: Int } } object Graph extends NodeTypes with ScrumptiousTypes with YummyTypes { case class Node() extends super.Node { override def allNodesHaveThis = 1 override def scrumptiousness = 2 // error: ScrumptiousTypes.Node has been disinherited override def yumminess = 3 } } If this works, it would be