Questions tagged [anonymous-class]
An anonymous class is a local class without a name. An anonymous class is defined and instantiated in a single succinct expression using the new operator.
anonymous-class
708
questions
1
vote
1
answer
39
views
Scala 2 to Scala 3: Instantiating a trait no longer recognises new methods
The following code compiles and runs in Scala 2:
trait SomeTrait {
val myName: String
}
class SomeClass() extends SomeTrait {
override val myName: String = "Billy Banana"
}
val ...
0
votes
0
answers
76
views
Function in anonymous Laravel Blade component
I'm working on a Laravel project and trying to create an anonymous Blade component that doesn't rely on a controller. I want this component to have a variable and a method that can be called within it ...
0
votes
3
answers
64
views
Refer to the properties of ancestors when instantiating and extending a class "in one shot"
Thanks to the answers to this question I am able to override a virtual method in C# when I extend a class into a kind of anonymous type.
But is it possible to refer to a class variable or property of ...
0
votes
1
answer
77
views
Java Anonymous class redefining
This is simple java program of anonymous class where class is redefined (not interface) as anonymous class.
class Anonymous {
int i = 10;
void main() {
System.out.println("...
0
votes
0
answers
51
views
Why do anonymous classes not implement System.IEquatable<T>?
Anonymous classes (a.k.a. anonymous types) are implicitly created and used by the C# compiler for code like this:
var obj = new { X1 = 0, X2 = 1 };
They have value equality semantics, i.e., the ...
1
vote
1
answer
76
views
Can we declare interface inside a method?
"You cannot declare an interface inside a block; interfaces are inherently static" This is sentence from https://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html#local-classes-...
0
votes
2
answers
101
views
Java: accessing a non-static field in an anonymous class in a static context
Consider the following class:
public class DataStructure {
// Create an array
private final static int SIZE = 15;
private int[] arrayOfInts = new int[SIZE];
public DataStructure()...
1
vote
1
answer
336
views
Why do I can't access to non-private member of anonymous object in Kotlin?
I am a java developer and now I am learning Kotlin.
I've met an interesting(working) piece of code:
class C {
private fun getObject() = object {
val x: String = "x"
}
...
0
votes
0
answers
14
views
.NET create anonymous type from another type but modifyng some fields
I have some class with "complex" objects like Enumerators, Lists and others. I need to construct the same anonymous object from instance of this class.
However, I need to convert all ...
0
votes
0
answers
49
views
How to write testng testcase for private final anonymous inner class
Public class Formatter{
private final SampleFormatter sampleFormatter = new SampleFormatter() {
@Override
public String formatDouble (int tag, double Value, int pre) {
if (Double.isNaN(Value))...
0
votes
1
answer
30
views
Why updating a primitive instance variable value referring by the method of an anonymous class does not update the value in the method of it?
Here is a problem I face when maintaining and old application, below are the code for demonstration:
First, I created a class with field innerComp valued by instance of an anonymous class and a field ...
3
votes
1
answer
52
views
Can static blocks and variables be used inside anonymous inner classes in Java?
Do static blocks and static variables work inside anonymous inner classes in java?
Hello, I was following a video explanation on YouTube and it was talking about the static blocks and the static ...
0
votes
1
answer
37
views
Java inner/anon classes
I'm stuck on this question where we need to instantiate the C class through A
class A{
static class B{}
static class C{ B b;
C(B b){this.b=b;}
int foo(){return 42;}
}
}
public class ...
0
votes
1
answer
133
views
How to find an anonymous class in the annotation processing environment?
I'm writing an annotation processor with Java 8.
Let's say I have a class like this somewhere in my project:
public class SampleClass {
public void foo(int i) {
new Runnable() {
...
1
vote
1
answer
80
views
Different Java compilers generate different class names for the same anonymous class
Names of anonymous classes are generated by concatenating the outer class name with a $ and a number, so e.g. anonymous classes within a class Foo may be generated as Foo$1, Foo$2, etc.
I have made ...