Given a simple entity relationship:
@Entity
public class Single {
@OneToMany
public Set<Multiple> multiples;
}
How does Hibernate find out that the generic type of multiples is Multiple? This information is impossible to find with the standard Reflection API.
I'm looking through the source code, but don't really know where to st...
Let me give example:
I have some generic class/interface definition:
interface IGenericCar< T > {...}
I have another class/interface that I want to relate with class above, for example:
interface IGarrage< TCar > : where TCar: IGenericCar< (any type here) > {...}
Basically, I want my generic IGarrage to be dependent on IGenericCar,...
Hi all,
I still have trouble with some corner cases in the java generics system.
I have this method (I'm only interested in the signature) :
interface Extractor<RETURN_TYPE> {
public <U extends Enum<U>> RETURN_TYPE extractEnum(final Class<U> enumType);
}
(think about an interface whose implementations sometimes extracts an En...
I've got a generic class:
public class BaseFieldValue<T>
{
public BaseFieldValue()
{
//...
}
public BaseFieldValue(string value)
{
//...
}
public BaseFieldValue(T value)
{
//...
}
}
Fine. Except...
var myValue = new BaseFieldValue<string>("hello");
Oops. The undesired co...
Hy,
i know it sounds a very stupid question.
Here's what i found:
public static List<SomeDTO> GetData(Guid userId, int languageId)
{
// Do something here
}
public static List<int> GetData(Guid userId ,int iNumberOfItems)
{
var result = GetData(userID,0);
return (from r in result select c.id).Take(iNumberOfItems)...
The following doesn't compile
public static T Retrieve<T>(this NameValueCollection collection, String key) where T : Object
{
if (collection.AllKeys.Contains(key))
{
try
{
val = (T)Convert.ChangeType((object)collection[key], typeof(T));
}
catch { }
}
return val;
}...
Lets say I have this class
class Child {
public string FirstName { get; set; }
public string LastName { get; set; }
}
class Container {
public List<Child> { get; set; }
}
I'm working on a deserializer of sorts and I want to be able to create and populate the Child list from the data retrieved. I've gotten this far (I've c...
I have a class Odp. I want to use TreeSet to keep a sorted collection of Odp objects. However, I've been having problems.
public class OdpStorage {
private TreeSet<Odp> collection = new TreeSet<Odp>();
public addOdp(Odp o) {
return collection.add(o);
}
public int size() {
return collection.size();...
I have a custom list which inherits from Generic.List<T> like this:
public class TransferFileList<T> : List<TransferFile> { .. }
When I set (where 'Files' is a TransferFileList<T>):
var files = uploadResponse.Files.Where(x => !x.Success).ToList()
the 'files' object resolves as System.Collections.Generic.List<TransferFile>, not Tran...
Note: This is similar, but not quite the same as this other question
I've implemented an IBusinessCollection interface. It dervies from both ICollection<T>, and the old-busted non-generic ICollection. I'd prefer to just dump the old busted ICollection, but I'm using WPF databinding with a CollectionView which wants me to implement the o...
Having being taught during my C++ days about evils of the C-style cast operator I was pleased at first to find that in Java 5 java.lang.Class had acquired cast method.
I thought that finally we have an OO way of dealing with casting.
Turns out Class.cast is not the same as static_cast in C++. It is more like reinterpret_cast. It will...
I've added some extension methods for strings to make working with some custom enums easier.
public static Enum ToEnum<T>(this string s)
{
return (Enum)Enum.Parse(typeof(T), s);
}
public static bool IsEnum<T>(this string s)
{
return Enum.IsDefined(typeof(T), s);
}
Note -- because of limitations of generic type constraints, I ...
What I have?
An object that is saved in a static variable and called whenever needed
This object interfaces with another application.
I have two collections (Generic Lists) in this object
Logs
And
"Data That Is PreFeteched" to be used later
Problem is when more than one person is trying to use this object (the object interfaces with...
Hi,
I am having some troubles passing a reference to an object which is of generic type. I have found a way around by creating a 'Object' and passing a reference to that rather than the original - but it seems to smell a bit to me. Is there a better way here or do I have to live with it?
I understand the first error but the second elu...
I am trying to create a generic list of references to PointF objects. (No, I am not looking to create a generic list of PointF objects.) However, the following line fails to compile:
Generic::List<PointF^> ^pointList; // Generates error C3225
On the other hand, creating an array of PointF references works without a problem as follows:...
I know there are very similar questions but im not sure that any of them are exactly what i need. I have 2 methods that do exactly the same thing (so i dont need to override or anything) the only difference is the parameter and return types.
public List<List<TestResult>> BatchResultsList(List<TestResult> objectList)
{
}
public List<...
The title basically says it all: if I have a java method that is generic in T, can I find out anything about T? In particular, can I check whether T implements a certain interface or extends a certain class?
I would like to do something like
public <T> List<T> doSth(List<T> l) {
if(T extends Comparable) {
// do one thing
} el...
I am using generics to translate Java code to C# and having trouble with containers of the sort:
public static class MyExtensions
{
public static void add(this List<object> list, object obj)
{
list.Add(obj);
}
public static void add(this List<string> list, string s)
{
list.Add(s);
}
}
It seems t...
Intro
I am building a plugin architecture in my app. The plugins implement a given Interface IBasePlugin, or some other interface which inherited from the base interface:
interface IBasePlugin
interface IMainFormEvents : IBasePlugin
The host is loading the plugin assemblies, and then creates the appropriate object of any class implem...
Edited:" I received a very pertinent answer from 'erickson', but there is a side problem (up-casting?) that was not explicitly covered in my original example and is not solved with his answer. I've extended the example to cover this other problem, and I've included it at the end of this post. Thanks for your help.
I'm currently facing a...