inner-classes

Call an activity method from a BroadcastReceiver class

隐身守侯 提交于 2019-12-17 07:32:41
问题 I know I can do an inner receiver class to call any method from my receiver But my main activity is too damn big and does a lot of things. So I will need a class that extends broadcast receiver but who isn't an inner class. And can call one method from my main activity. I don't know if it's possible but my activity is a Home activity and a "singleInstance" activity so maybe with this detail someone has a way to access to my activity. If it's impossible any way to split some java code in

Why do inner classes make private methods accessible?

夙愿已清 提交于 2019-12-17 05:50:22
问题 I don't understand why this compiles. f() and g() are visible from the inner classes, despite being private. Are they treated special specially because they are inner classes? If A and B are not static classes, it's still the same. class NotPrivate { private static class A { private void f() { new B().g(); } } private static class B { private void g() { new A().f(); } } } 回答1: (Edit: expanded on the answer to answer some of the comments) The compiler takes the inner classes and turns them

Private inner classes in C# - why aren't they used more often?

只谈情不闲聊 提交于 2019-12-17 05:34:16
问题 I am relatively new to C# and each time I begin to work on a C# project (I only worked on nearly mature projects in C#) I wonder why there are no inner classes? Maybe I don't understand their goal. To me, inner classes -- at least private inner classes -- look a lot like "inner procedures" in Pascal / Modula-2 / Ada : they allow to break down a main class in smaller parts in order to ease the understanding. Example : here is what is see most of the time : public class ClassA { public MethodA(

Inner class within Interface

醉酒当歌 提交于 2019-12-17 02:41:47
问题 Is it possible to create an inner class within an interface? If it is possible why would we want to create an inner class like that since we are not going to create any interface objects? Do these inner classes help in any development process? 回答1: Yes, you can create both a nested class or an inner class inside a Java interface (note that contrarily to popular belief there's no such thing as an " static inner class ": this simply makes no sense, there's nothing "inner" and no "outter" class

Nested Class Parcelable [duplicate]

ぃ、小莉子 提交于 2019-12-16 18:02:10
问题 This question already has answers here : How can a Java class have no no-arg constructor? (8 answers) Closed 2 years ago . I need to know how to make a nested class Parcelable . When I create a nested class I get an error (it requires the parcel as a param.) Code: public class BookingDetailsItem implements Parcelable { private ServiceProviderItem serviceProvider; public Appointment appointmentDetails; private String notes; public BookingDetailsItem(ServiceProviderItem serviceProvider) { this

import class in different directory

核能气质少年 提交于 2019-12-14 02:33:32
问题 Actually, I am trying to finish this practice in "Think in Java" for self-learning purpose -- Exercise 6: (2) Create an interface with at least one method, in its own package. Create a class in a separate package. Add a protected inner class that implements the interface. In a third package, inherit from your class and, inside a method, return an object of the protected inner class, upcasting to the interface during the return. so I created a class named IgetResult.java under directory "a"

Nesting an object in a class [closed]

吃可爱长大的小学妹 提交于 2019-12-13 22:23:26
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Using C++ I'm trying to nest an object of one class inside another class and I get a syntax error on line 6 of CarpetClass.h that says Error: fuction "Rectangle" is not a type name myclass.h class Rectangle{ private: double length; double width; public: void setLength(double len){ length = len; } void setWidth

calling a method from an onClick listener [duplicate]

可紊 提交于 2019-12-13 10:03:33
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Accessing the containing class of an inner class in Java I know this has certainly been answered before, but I have been working on this for two straight nights and I either don't understand or I have messed something up badly. I am trying to call a method with a button. My method is only going to copy and paste so it's not opening another activity. package com.example.copypastetest; import android.app.Activity;

Puzzle on Inner Classes and Class Hiding

倾然丶 夕夏残阳落幕 提交于 2019-12-13 09:26:03
问题 I have a sample code to solve which is based on inner classes: package inner; class A { void m() { System.out.println("Outer"); } } public class TestInner { public static void main(String[] args) { new TestInner().go(); } private void go() { new A().m(); class A{ void m(){ System.out.println("Inner"); } } new A().m(); } class A{ void m(){ System.out.println("Middle"); } } } The output given by above sample code is: Middle Inner And my question is, given that I dont want to use the package

Accessing private instance variable of inner class from outer class

狂风中的少年 提交于 2019-12-13 04:14:00
问题 Why isn't this code working public class BB { private class A { private int x; } public static void main(String[] args) { A a = new A(); a.x = 100; System.out.println(a.x); } } while this code is working? public class BB { private class A { private int x; } static int y = 3; public static void main(String[] args) { BB b = new BB(); b.compile(); System.out.println("y = "+ y); } public void compile() { A a = new A(); a.x = 100; System.out.println(a.x); System.out.println("y = "+ y); } } In