716 questions
2
votes
2
answers
98
views
Declaring aliases for anonymous classes
This is an attempt to make an alias to an anonymous class:
struct {
int i = 0;
} a;
// error C7626 in MSVC
using A = decltype(a);
This produces an error in Visual Studio:
error C7626: unnamed ...
0
votes
1
answer
77
views
Can nested classes or even anonymous classes extend a class or implement a interface? [closed]
Can nested classes or anonymous classes extend a class or implement an interface in Java? If so, are there any limitations or things I should be aware of? I'm not very familiar with nested classes, ...
0
votes
1
answer
88
views
How to write test for Trait
I have a Trait called HasDefault
its main purpose is to ensure that the class has a static field $default which is callable and returns the default instance of the class using the Trait
This is what ...
2
votes
1
answer
54
views
Anonymous classes can refer to inaccessible type in the signature of the supertypes?
Consider the following clause from JLS 8: § 15.9.5.1. Anonymous Constructors
Note that it is possible for the signature of the anonymous constructor to refer to an inaccessible type (for example, if ...
1
vote
1
answer
47
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
3
answers
87
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 ...
1
vote
0
answers
69
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 ...
0
votes
2
answers
122
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()...
0
votes
0
answers
16
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
1
answer
41
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 ...
0
votes
1
answer
42
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 ...
1
vote
1
answer
120
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 ...
2
votes
2
answers
206
views
getting value from callback kotlin
Trying to make a file downloadManager
we have a activity which contains recycler view, each item in recycler view represents a file which is either in downloading, downladed state. Each recycler view ...
0
votes
2
answers
429
views
What is a difference between refinement type and anonymous subclass in Scala 3?
Anonymous class definition is
An anonymous class is a synthetic subclass generated by the Scala
compiler from a new expression in which the class or trait name is
followed by curly braces. The curly ...
4
votes
1
answer
426
views
Cast to bool nullable of null value VS default value of bool nullable
Is there any difference between those two ways to write the same thing?
int? foo = GetValueOrDefault();
var obj = new
{
//some code...,
bar = foo.HasValue ? foo > 0 : (bool?)null
}
VS
int? ...
-1
votes
1
answer
76
views
How to 'pass' methods to anonymous class
I am writing automated tests, and I want each to retry twice. So I wrote a method:
public void retry(int retries, Retryable retryable) {
for (int i = 0; i < retries; i++) {
...
0
votes
0
answers
129
views
Return an anonymous class from factory function
I am trying to instantiate an anonymous class via a factory function.
Unfortunately for me, the function returns the exact same class for each call, which is getting me in trouble while using static ...
1
vote
2
answers
218
views
How do I restart the timer countdown
I am trying to reset the timer so it can pull another value from my array.
Does anyone know the solution? My error is saying:
peat = peat= 1;
local variables referenced from an inner class must be ...
-3
votes
1
answer
336
views
Can we create an anonymous inner class from a concrete class?
There is something surprising in the following code. The ListCell class is not abstract, but we were able to create an anonymous class from it and override its method! How is this possible?
ListCell&...
2
votes
1
answer
111
views
How to replace the listeners with anonymous classes in Java?
I have an interface called ClientRegistrationListener
public interface ClientRegistrationListener {
void onClientAdded(Client client);
}
And I also have in the main class an ArrayList of ...
0
votes
1
answer
138
views
Ensuring anonymous objects in C# all have certain common properties
I have a problem regarding anonymous objects in C#. The situation is as follows:
I have a C# web app which does NOT use the traditional ASP.NET Razor engine, but instead uses the RazorEngine open ...
1
vote
1
answer
44
views
Is there a way to invoke a non-overridden or non-implemented method in an anonymous class outside of its definition?
There are 3 method signatures in a Phone interface, all of which were implemented in the anonymous class definition for a smartphone. However, I want the anonymous class to have another method that is ...
0
votes
2
answers
4k
views
Error: method X must override or implement a supertype method
I'm using JUnit 5, and copied the code from "Software Testing" book in order to create a mock object for testing. part of the tester code is:
@Test
public void ...
2
votes
0
answers
39
views
Why does local variable in Java have to be final in lambda (or anonymous class), but in Kotlin it doesn't have to? [duplicate]
Java: In this method, compiler gives error "Variable used in lambda expression should be final or effectively final":
void javaAnonymousClass(Button button) {
String localVar = "10&...
2
votes
1
answer
424
views
Is there really an Anonymous class/struct in C++?
I'm confused by many websites: People there refer to a class/struct as Anonymous when it has no name for example:
struct{
int x = 0;
}a;
I think the example above creates an Unnamed struct but not ...