I am new to Generics. I have worked through the following Sun trail, but think Generics are completely pointless:
http://download.oracle.com/javase/tutorial/java/generics/generics.html
Am I missing something fundamental? Because it seems to be that, if the argument was an Integer rather than an Object, you'd get the same behaviour as ...
Hi,
Here's the relevant code:
public interface Artifact {}
public interface Bundle implements Artifact {}
public interface Component implements Artifact {}
public interface State<T extends Artifact> {
void transition(T artifact, State<T> nextState);
}
This allows me to define this enum:
enum BundleState implements State<Bun...
I'm looking at the MSDN docs about List.GetEnumerator.
They say the C# method signature is:
public List<(Of <(<'T>)>)>..::..Enumerator GetEnumerator()
I was expecting this much simpler signature:
public List<T>.Enumerator GetEnumerator()
What does their signature mean, with all the punctuation and the "Of" keyword?
Edit: Well, I ...
I have the following repository that I use for unit testing:
public class MyTestRepository<T>
{
private List<T> entities = new List<T>();
public IQueryable<T> Entities
{
get { return entities.AsQueryable(); }
}
public T New()
{
//return what here???
}
public void Create(T entity)
{
...
This must be a Delphi bug...
I have a unit which is the basis of my persistance framework. In that unit I have a base class for all my domain objects, a list class and a generic list class.
Just recently I noticed that when I step into the unit when debugging, execution will jump to a point a little further down in the file than it sho...
I would like to parameterize a type with one of its subclasses. Consider the following:
class DataLoader {
class Data { /* data specifics to this data loader */ }
def getData : Data /* and so on */
}
Now I want to make this loader able to asynchronously retrieve data from the network. One of the options is to have it subclass Call...
package pkg_2;
import java.util.*;
class shape{}
class Rect extends shape{}
class circle extends shape{}
class ShadeRect extends Rect{}
public class OnTheRun {
public static void main(String[] args) throws Throwable {
ShadeRect sr = new ShadeRect();
List<? extends shape> list = new LinkedList<ShadeRect>(); ...
List listOne = new LinkedList<Shxx>();
List<Shxx> listTwo = new LinkedList<Shxx>();
List listThree = new LinkedList();
List<Shxx> listFour = new LinkedList();
...
I want to create a method that compares a number but can have an input that is any of the subclasses of Number.
I have looked at doing this in the following manner...
public static <T extends Number> void evaluate(T inputNumber) {
if (inputNumber >= x) {
...
}
}
I need to get the actual primative before I can perform the comp...
public T Update(T update) { }
Currently for this method I m implementing it like so..is there any other easy way around in Linq to SQL
public T Update (T update)
{
var table = (IEnumerable<T>)(_table.AsQueryable());
var store = (T)((from a in table.Where(
a => a.GetType().GetPrimaryKey() ==
update.GetType(...
listSuper
listSub_A
listSub_B
Is there any extension methods that replace the following piece of code?
foreach(int a in listSuper)
{
if (!listSub_A.Contains(a))
{
listSub_B.Add(a);
}
}
In short I want to fill listSub_B with elements in listSuper which are not in listSub_A.
...
I've got the following JAXB unmarshalling code which I'm trying to generalize. Here's what it looks like:
private Object getResponseObject(String stubbedXmlFile,
Class jaxbInterfaceClass,
AbstractRepository repository) {
Object responseObject = null;
try {
JAXBContext jc = JAXBContext.newInstance(jaxbIn...
I have some objects like user, address and so on, and Im converting them to business objects using extension methods:
public static UserModel ToPresentationForm(this User pUser)
{
return new UserModel
{
...
map data
...
};
}
Also I need to convert strongly typed collections...
I want to make an extension method to check if an enumeration has a flag.
DaysOfWeek workDays = DaysOfWeek.Monday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday;
// instead of this:
if ((workDays & DaysOfWeek.Monday) == DaysOfWeek.Monday)
...
// I want this:
if (workDays.ContainsFlag(DaysOfWeek.Monday))
...
How can I accomplish th...
Hi All, I want to create a method which will take some base type as a parameter and compares and check if it is derived type and return the derived type based on that.
For Example:
Class A : IBase
Class B : IBase
My method:
Public IBase GetData(IBase type)
{
If type is A then
{
//do smthing
return A
}
If type is B
{
...
Hi,
I noticed that the Ninject API has calls such as
Bind<ISomething>().DoSomethingElse();
How is this achieved?
...
Hello chaps
I have two almost identical c# functions. Because they're so similar I thought I'd try out generics, but I'm stumped on how to do it. Any suggestions, or am I barking up the wrong tree entirely?
public IList<UnitTemplate> UnitTemplates { get; set; }
public IList<QualTemplate> QualTemplates { get; set; }
public ...
Having this design :
interface Foo<T> {
void doSomething(T t);
}
class FooImpl implements Foo<Integer> {
//code...
}
interface Bar extends Foo {
//code...
}
class BarImpl extends FooImpl implements Bar {
//code...
}
It gives me Compile Error :
The interface Foo cannot be
implemented more than once with
differ...
I have written a function template and an explicitly specialized templated function which simply takes in 3 arguments and calculates the biggest among them and prints it.
The specialized function is causing an error,whereas the template works fine.
But I want to work with char* type.
This is the error I get=>
error: template-id ‘Max<>...
I have the following problem:
Given a Guice type literal TypeLiteral<T> template and a class Class c implementing or extending T, construct a type Type t which is equivalent to c with all type variables instantiated so as to be compatible with template.
If c has no type variables, it's easy; c is the type in question. However, if ...