The name is a little blurry, so here's the situation:
I'm writing code to use some 'trajectories'. The trajectories are an abstract thing, so I describe them with different interfaces. So I have a code as this:
namespace Trajectories {
public interface IInitial<Atom>
{
Atom Initial { get; set; }
}
public interf...
I've got some code that creates a list of AD groups that the user is a member of, with the intention of saying 'if user is a member of GroupX then allow admin access, if not allow basic access'.
I was using a StringCollection to store this list of Groups, and intended to use the Contains method to test for membership of my admin group, ...
In Java, how can I construct a Type object for Map<String, String>?
System.out.println(Map<String, String>.class);
doesn't compile. One workaround I can think of is
Map<String, String> dummy() { throw new Error(); }
Type mapStringString = Class.forName("ThisClass").getMethod("dummy", null).getGenericReturnType();
Is this the correc...
This might be a stupid question, but I just saw a question asking how to create a Type variable for a generic type. The consensus seemed to be that you should have a dummy method returning that type, and then use reflection to get it (in this case he wanted Map<String, String>). Something like this :
public Map<String, String> dummy() {...
I have need to cast a generic list of a concrete type to a generic list of an interface that the concrete types implement. This interface list is a property on an object and I am assigning the value using reflection. I only know the value at runtime. Below is a simple code example of what I am trying to accomplish:
public void Employ...
Given the following interfaces/classes:
public interface IRequest<TResponse> { }
public interface IHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
TResponse Handle(TRequest request);
}
public class HandlingService
{
public TResponse Handle<TRequest, TResponse>(TRequest request)
where TRequest : ...
It's obvious that a parent class's object can hold a reference to a child, but does this not hold true in case of parameterised collection ??
eg:
Car class is parent of Sedan
So
public void doSomething(Car c){
...
}
public void caller(){
Sedan s = new Sedan();
doSomething(s);
}
is obviously valid
But
public void do...
The code I'm writing receives an ArrayList from unmanaged code, and this ArrayList will always contain one or more objects of type Grid_Heading_Blk. I've considered changing this ArrayList to a generic List, but I'm unsure if the conversion operation will be so expensive as to nullify the benefits of working with the generic list. Curren...
There are plenty of questions on stackoverflow from people who have attempted to create an array of generics like so:
ArrayList<Foo>[] poo = new ArrayList<Foo>[5];
And the answer of course is that the Java specification doesn't allow you to declare an array of generics.
My question however is why ? What is the technical reason under...
Event dispatcher interface
public interface EventDispatcher {
<T> EventListener<T> addEventListener(EventListener<T> l);
<T> void removeEventListener(EventListener<T> l);
}
Implementation
public class DefaultEventDispatcher implements EventDispatcher {
@SuppressWarnings("unchecked")
private Map<Class, Set<EventListener>> lis...
(For this example) ListBox l is bound to CustomObjectCollection c.
Does l call c's Constructor?
What if c is a Generic Object?
**In XAML (1)**
<ListBox Content={Binding CustomObjectCollection}/>
**In Codebehind**
CustomObjectCollection<MyClass> c;
**In XAML (2)**
<ListBox Content={Binding CustomObjectCollection}/>
Suppose in c, I po...
Is it to maintain backwards compatibility with older (un-genericized) versions of Collection? Or is there a more subtle detail that I am missing? I see this pattern repeated in remove also (remove(Object o)), but add is genericized as add(E e).
...
I'm trying to create a generic list from a specific Type that is retrieved from elsewhere:
Type listType; // Passed in to function, could be anything
var list = _service.GetAll<listType>();
However I get a build error of:
The type or namespace name 'listType' could not be found (are you missing a using directive or an assembly refere...
I have the following method, I wish to remove items from my collection that match the product Id. Seems fairly straight forward, but i get an exception. Basically my collection is getting out of sync. So what is the best way to remove an item from a collection.
public void RemoveOrderItem(Model.Order currentOrder, int productId)
{
...
Hi there!
I'm trying to invoke a method with reflection that has a generic return type, like this:
public class SomeClass<T>
{
public List<T> GetStuff();
}
I get an instance of SomeClass with a call to a Repository's GetClass<T> generic method.
MethodInfo lGetSomeClassMethodInfo = typeof(IRepository)
.GetMethod("GetClass...
This is Cocoa Touch (et al), iPhone, XCode only.
After completing my first commercial iPhone app, I'm struggling a bit to find a way to start and expand an app from scratch which gives the most linear development (i.e., the least scrapping, re-write or re-organization of code, classes and resources) as app specs change and I learn more...
Here is a small currency converter piece of code:
public enum CurrencyType {
DOLLAR(1),
POUND(1.2),
RUPEE(.25);
private CurrencyType(double factor) {
this.factor = factor;
}
private double factor;
public double getFactor() {
return factor;
}
...
2 questions in one, but very much related.
Is it possible with Castle Windsor to resolve a configuration entry such as -
Assembly.Namespace.Object1`2[[${ComponentId1}],[${ComponentId2}]], Assembly
Where ComponentId1 and ComponentId2 are defined as components. Castle Windsor doesn't seem to be resolving the ComponentId, it is just look...
The following code compiles perfectly with Eclipse, but fails to compile with javac:
public class HowBizarre {
public static <P extends Number, T extends P> void doIt(P value) {
}
public static void main(String[] args) {
doIt(null);
}
}
I simplified the code, so T is not used at all now. Still, I d...
I want to make a map-kind of container that has the following interface:
public <T> Thing<T> get(Class<T> clazz);
public <T> void put(Class<T> clazz, Thing<T> thing);
The interesting point is that the Ts in each Class<T> -> Thing<T> pair is the same T, but the container should be able to hold many different types of pairs. Initially I...