Delphi 2010
How to modify TList < record > value ?
type TTest = record a,b,c:Integer end;
var List:TList<TTest>;
A:TTest;
P:Pointer;
....
....
List[10] := A; <- OK
List[10].a:=1; <- Here compiler error : Left side cannot be assined to
P:=@List[10]; <- Error: Variable requied
...
Hi
I have created a List data structure implementation for generic data type with each node declared as following.
struct Node
{
void *data;
....
....
}
So each node in my list will have pointer to the actual data(generic could be anything) item that should be stored in the list.
I have following signature for adding a node to...
In .NET the BinarySearch algorithm (in Lists, Arrays, etc.) appears to fail if the items you are trying to search inherit from an IComparable instead of implementing it directly:
List<B> foo = new List<B>(); // B inherits from A, which implements IComparable<A>
foo.Add(new B());
foo.BinarySearch(new B()); // InvalidOperationException,...
Is there any practical difference between the following approaches to print all elements in a range?
public static void printA(Iterable<?> range)
{
for (Object o : range)
{
System.out.println(o);
}
}
public static <T> void printB(Iterable<T> range)
{
for (T x : range)
{
System.out.println(x);
}
}...
I've a collection type:
Collection<A> collecA
And I've a list in my object:
List<B> listB
Where B is extending A
class B extends A { ... }
But I can't do the following:
collecA = listB
I can't understand why since Collection is implemented by List.
...
Hey Everyone,
I was wondering if anyone could look over a class I wrote, I am receiving generic warnings in Eclipse and I am just wondering if it could be cleaned up at all. All of the warnings I received are surrounded in ** in my code below.
The class takes a list of strings in the form of (hh:mm AM/PM) and converts them into HourMi...
I want to determine if a field is typed as the subclass of a generic type.
For e.g
Foo extends Bar<Foo>
Foo x;
How do I tell if the field x is typed as a subtype of Bar<Foo>?
...
Hello guys, I have a generic IRepository that has 2 constructors, one have none parameters, other has the datacontext as parameter.
I want to define to structuremap to aways in this case use the parameterless constructor.
I want a way to create a parameterless contructor, other solutions that I have seen, they create a new Datacontext a...
I have the following model where I just modified my IEntity interface to take a generic type since I have multiple identity types.
public interface IEntity<T>
{
T Id { get; set; }
}
public class Product : IEntity<int>
{
public int Id { get; set; }
}
Now I have to modify my IRepository and IProductRepository to reflect this ch...
I know this is probably a dupe, but I can't for the life of me remember what the name is or even how to look it up.
I know T would the the Type you are casting to, but what is the technical name of it.
Edit
Here is a link for more information on Generics
http://stackoverflow.com/questions/99686/why-do-c-and-vb-have-generics-what-benef...
Ok so I'm currently working with a set of classes that I don't have control over in some pretty generic functions using these objects. Instead of writing literally tens of functions that essentially do the same thing for each class I decided to use a generic function instead.
Now the classes I'm dealing with are a little weird in that t...
I alredy have this:
public static object GetDBValue(object ObjectEvaluated)
{
if (ObjectEvaluated == null)
return DBNull.Value;
else
return ObjectEvaluated;
}
used like:
List<SqlParameter> Params = new List<SqlParameter>();
Params.Add(new SqlParameter("@EntityType", GetDBValue(EntityType)));
Now i wanted to keep the sam...
Hi. I have a class called NTree:
class NTree<T>
{
delegate bool TreeVisitor<T>(T nodeData);
public NTree(T data)
{
this.data = data;
children = new List<NTree<T>>();
_stopTraverse = false;
}
...
public void Traverse(NTree<T> node, TreeVisitor<T> visitor)
{
try
{...
Why does this work? I'm not complaining, just want to know.
void Test()
{
int a = 1;
int b = 2;
What<int>(a, b);
// Why does this next line work?
What(a, b);
}
void What<T>(T a, T b)
{
}
...
why do I get a compiler error in the following code stating: Cannot implicty convert type SpecialNode to T even though T must derive from NodeBase as I defined in the where clause and even though SpecialNode actually derived from NodeBase?
public static T GetNode<T>() where T : NodeBase
{
if (typeof(T) == typeof(SpecialN...
I have come across a strange behavior of Java that seems like a bug. Is it? Casting an Object to a generic type (say, K) does not throw a ClassCastException even if the object is not an instance of K. Here is an example:
import java.util.*;
public final class Test {
private static<K,V> void addToMap(Map<K,V> map, Object ... vals) {
...
I want to have a function defined in a superclass that returns an instance of the subclass that is used to invoke the function. That is, say I have class A with a function plugh. Then I create subclasses B and C that extend A. I want B.plugh to return a B and C.plugh to return a C. Yes, they could return an A, but then the caller would h...
What is the difference between this method declaration:
public static <E extends Number> List<E> process(List<E> nums){
and
public static List<Number> process(List<Number> nums){
Where would you use the former?
...
Questions:
What are raw types in Java, and why do I often hear that they shouldn't be used in new code?
What is the alternative if we can't use raw types, and how is it better?
Similar questions
Should Java Raw Types be Deprecated?
...
Hi All,
Let me define the problem first and why a messagequeue has been chosen. I have a datalayer that will be transactional and EXTREMELY insert heavy and rather then attempt to deal with these issues when they occur I am hoping to implement my application from the ground up with this in mind.
I have decided to tackle this problem b...