anonymous-class

Real advantages of .Net delegates over Java's anon classes?

I know a lot of the uses of .Net delegates can be emulated in Java by using a combination of interfaces and anonymous classes, but are there any situations where delegates have a real advantage and there is no Java equivalent? ...

Private inner class synthesizes unexpected anonymous class

When you compile a Java class with a private inner class, it appears that an anonymous class is automatically synthesized along with it for some reason. This class is sufficient to reproduce it: public class SynthesizeAnonymous { public static void method() { new InnerClass(); } private static class InnerClass {} } ...

Column of BindingSource with Anonymous Class as DataSource

Is there any method to select a column of the current row of a BindingSource whose DataSource is an anonymous class? var userResults = from u in dataContext.Users join c in dataContext.Computers on u.ID equals c.UserID where doSearch && u.Name.Contains(userNameTextBox.Text) && u.UserName.Contains(userUsername...

c#: Cast to Anonymous Type

Hi I had the following problem today, and i was wondering if there is a solution for my problem. My idea was to build anonymous classes and use it as a datasource for a WinForm Bindingsource: public void Init() { var option1 = new { Id = TemplateAction.Update, ...

Anonymous inner class in groovy

I am looking into the groovy-wicket integration and lack of anonymous inner classes seems to be a problem when writing the event handlers. Is there a groovier way of writing this code import org.apache.wicket.PageParameters import org.apache.wicket.markup.html.basic.Label import org.apache.wicket.markup.html.link.Link import org.apache....

Creating a dynamic anonymous types vairables

Hello, I would like to ask if i can create a anonymous type variable and later on i can add more Properties? like var x = new { Name = "Ahmed" }; and want to add Age to it? how i can do this? Another question: i saw on some blogs a type AnonymousType what is the name space for this class? here is am example http://www.codeproject.com/KB...

Serializing a list of anonymous delegates.

This question may be very similar to my one, but I cannot see the answer I need in it. I have a class, called CASM, that has a List<Action>. I want to serialize this class (using the BinaryFormatter or something similar). This class and all classes referenced in the Actions have got correct [Serializable] and [NonSerializable] attributes...

Java reflection: How can I retrieve anonymous inner classes?

Hello, everyone! I have an anonymous inner class inside another class (SomeClass). Both SomeClass.class.getClasses() and SomeClass.class.getDeclaredClasses() return empty arrays. I couldn't find some hints on this in Class' Javadocs. Can anonymous inner classes be retrieved using reflection in some way? What else are notable differe...

Java: Access local variables from anon inner class? (PriorityQueue)

I want to use a PriorityQueue to do a topological sort on a graph. For brevity, I'd like to use an anonymous inner class for the comparator. However, I need access to the graph g in order to determine the in degree of the nodes I'm looking at. Is this possible? /** * topological sort * @param g must be a dag */ public static Queue<...

Anonymous class question

Hi, I've a little doubt over this line: An anonymous class cannot define a constructor then, why we can also define an Anonymous class with the following syntax: new class-name ( [ argument-list ] ) { class-body } ...

Reference to Public Enum results in Anonymous Class

I'm getting an anonymous class at compile-time that I'm not expecting. Relevant code follows, then a more detailed explanation: Entirety of CircuitType.java: public enum CircuitType { V110A20, V110A30, V208A20, V208A30 } From Auditor.java, lines 3-9: public class Auditor { private String[] fileNames; private int numV110A20; ...

Private variables/methods in anonymous class?

Hello. I have created an anonymous class in which I declare a few variables and methods. My java teacher tells me to make these private. I don't see how changing the modifier makes any difference since these variables and methods are private to the anonymous class anyway, so I prefer to have no modifier at all. Who is right and what make...

Is Java "caching" anonymous classes?

Consider the following code: for(int i = 0;i < 200;i++) { ArrayList<Integer> currentList = new ArrayList<Integer>() {{ add(i); }}; // do something with currentList } How will Java treat the class of currentList? Will it consider it a different class for each of the 200 objects? Will it be a performance hit even after the fir...

How do I simulate anonymous classes in C#

I'm writing a small data structures library in C#, and I'm running into an architectural problem. Essentially I have a class which implements the visitor pattern, and there are many possible implementations of visitors: public interface ITreeVisitor<T, U> { U Visit(Nil<T> s); U Visit(Node<T> s); } public abstract class Tree<T> ...

Virtual tables on anonymous classes

I have something similar to this in my code: #include <iostream> #include <cstdlib> struct Base { virtual int Virtual() = 0; }; struct Child { struct : public Base { virtual int Virtual() { return 1; } } First; struct : public Base { virtual int Virtual() { return 2; } } Second; }; int main() { Child child; ...

Creating anonymous class as custom key in dictionary.

While using dictionary, i always override GetHashCode and Equals ( or provide a custom comparer to the dictionary). What happens behind the covers when i create an anonymous class as key? Sample Code.... var groups=(from item in items group item by new { item.ClientId, item.CustodianId, item.CurrencyId } ...

Referring to non-final fields of an enclosing class inside an anonymous inner class in Java

In Java, I know that it is possible to do something like this: public class Greeter { public void greetEventually() { final String greeting = "Hello!"; Job j = new Job() { public void run() { System.out.println(greeting); } }; j.schedule(); } } This would ...

Speed difference between anonymous class and IDictionary<string,object> for htmlAttributes in ASP.NET MVC

I am trying to optimize my ASP.NET MVC application using some techniques that include URL generation tweaking a la: http://www.chadmoran.com/blog/2009/4/23/optimizing-url-generation-in-aspnet-mvc-part-2.html If the speed difference is so large between using RouteValueDictionary in place of anonymous classes, then should I also look to u...

Access outer variable from inner anonymous Runnable

The following example code (SSCCE) complains that local variable a must be final. public class Foo { final List<A> list = new ArrayList() {{ add(new A()); }}; void foo() { A a; Thread t = new Thread(new Runnable() { public void run() { a = list.get(0); // not good ! } ...

Anonymous class with MooTools.

Can I create the anonymous class(java term) using the MooTools js framework? Suppose it should look like: A = new Class({ invoke: function() { alert('class'); } }); a = new A({ invoke: function() { this.parent(); alert('instance'); }, }); But I don't want to modify constructor interface around to accept additiona...