two class:
public class BaseDo<K> {
protected K id;
public K getId() {
return id;
}
public void setId(K id) {
this.id = id;
}
}
public class BeanDo extends BaseDo<Integer> {
private String beanName;
public String getBeanName() {
return beanName;
}
public void setBeanName(...
Suppose I have these interfaces:
public interface I1 {
void foo();
}
public interface I2 {
void bar();
}
and the classes:
public class A extends AParent implements I1, I2 {
// code for foo and bar methods here
}
public class B extends BParent implements I1, I2 {
// code for foo and bar methods here
}
public class C extend...
Is this valid Java?
import java.util.Arrays;
import java.util.List;
class TestWillThatCompile {
public static String f(List<String> list) {
System.out.println("strings");
return null;
}
public static Integer f(List<Integer> list) {
System.out.println("numbers");
return null;
}
publ...
After reviewing this blog by Kirill Osenkov (How to create a generic List of anonymous types?) I am trying to do something a little more advanced and having issues.
The following code compiles:
var anon = new { One = "1", Two = "2" };
var result = DoSomething(anon);
public static T DoSomething<T>(T value)
{
ret...
One particular aspect of some code I've written is causing me minor headaches, I can't pinpoint the reason - all the type checking and casting is making me feel uneasy. The code works as it is right now. I'd like to know wether or not there's a better way to handle the type-specific aspects of the code.
I'm using a non-generified, objec...
(Not really sure if I phrased the question correctly...)
I want to create a lambda expression that would take an Object, attempt to convert it to a passed-in Type, and print to the console whether it was successful or not.
At a glance, the lambda expression may seem a pretty silly way to accomplish this task, but I'd really like to kno...
Hi All,
I am trying to use Delphi 2010's TObjectDictionary generic.
I would like to pass an enumerator of the Values property of that generic class, and the compiler doesn't seem to want to let me... Example:
TAttributeStates = class(TInterfacedObject, IAttributeStates)
private
FStates: TObjectDictionary<TPatchAttribute, TAttr...
Can anyone explain to me why GetInterfaces() in the below code returns an interface type that has FullName = null?
public class Program
{
static void Main(string[] args)
{
Type[] interfaces = typeof (Data<>).GetInterfaces();
foreach (Type @interface in interfaces)
{
Console.WriteLine("Name='{0...
This compiles:
class ReplicatedBaseType
{
}
class NewType: ReplicatedBaseType
{
}
class Document
{
ReplicatedBaseType BaseObject;
Document()
{
BaseObject = new NewType();
}
}
But this does not:
class DalBase<T> : where T: ReplicatedBaseType
{
}
class Document...
I am trying to use a common technique to create objects from Xml. (Xml is legacy, so although there are already libraries to do this, it seemed faster to write this myself.)
I don't understand the compiler's complaint about the generic usage. Code sample:
public void createObjects() {
List<Object1> objectOnes = new ArrayList<Object1...
Let's say I have several POJOs which all extend a common supertype, BaseObject.
I have a GenericDao which is declared as public interface GenericDao<T>.
For each type-specific DAO, I have an interface which extends the generic type and restricts it to a concrete type (public interface UserDao extends GenericDao<User>) and then an impl...
Is there a way to cast a dictionary i a one-liner and without all the overhead in C# .net 3?
var result = new Dictionary<string, AccessoryVariant>();
foreach (BaseVariant variant in mVariants.Values)
{
result.Add(variant.Id, (AccessoryVariant)variant);
}
return result;
I would like to do something like this:
return (Dictionary<st...
I have a number of "section items" (Lesson, Info) which inherit from the common type SectionItem. The various types of SectionItems share some but not all properties.
I have found the best way to pass parameters to each kind of object is to pack them all in a Dictionary<string, object> and then let the base class SectionItem unpack the...
How can I pass a parameter to a Java method with a raw type in its method signature? My example API is as follows:
class P<T> {}
class Q {
public void f(P p[]) {}
}
And my attempt to call it from Scala looks like this:
val q = new Q()
val p = new P()
val p_array = Array(p)
q.f(p_array)
Which generates the following compiler e...
Hi,
Here's the situation:
I'm attempting to get a collection of all types in my assembly that implement a specific generic interface along with the generic type parameters used. I have managed to put together a Linq query to perform this but it seems awfully redunant.
I've read up on let and joins but couldn't see how to I'd use them t...
The Align plugin is all nice and dandy, but I encounter problems with it when dealing with generics generics such that:
HashMap<String, Object> session = new HashMap();
ArrayList<String> names = new ArrayList();
String banana = "Yo banana boy";
int count = 0;
After \adec it becomes:
HashMap<String, Object> session = new HashMap();
Ar...
class SomeClass<E> {
Map<String, String> someMethod();
}
And usage
SomeClass a = new SomeClass();
a.someMethod().get("foo") // returns object, not string!
//This code would not even compile
String s = a.someMethod().get("foo");
But if I remove generalization (<E>) from SomeClass -- it works.
It...
I have the following class:
public class MyClass<T> where T : class
{
public void Method1<TResult>(T obj, Expression<Func<T, TResult>> expression)
{
//Do some work here...
}
public void Method2<TResult>(T obj, Expression<Func<T, TResult>> expression1, Expression<Func<T, TResult>>...
Hello
Does anyone know why the following code does not compile and during compilation I get incompatible types exception ?
public class Test<T> {
public static void main(String[] args)
{
// using Test<?> solves the compilation error
Test test = new Test();
// getting error incompatible types:
// found : java.lang.Ob...
Given the following two classes:
public class ABC
{
public void Accept(Ordering<User> xyz)
{
// Do stuff with xyz...
}
}
public class Ordering<TEntity>
where TEntity : class
{
private readonly Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> Transform;
private Ordering(Func<IQueryable<TEntity>,...