Hi,
I transitioned from Java 1.4(previous company) to Java 1.6 (new company). What I have observed that in case of 1.4 most of the proprietary frameworks were defined using interfaces and template patterns, whereas with 1.6 most of the frameworks are defined around generics.
While I am still trying to get a grip around Generics, my q...
Recently I was working on implementing a small snippet that caches my results and the way I was doing it was using a Dictionary as follows:
private Dictionary<ID, IQueryable<Results>> _simpleCache;
The idea was to search for all the results that have the id specified by 'ID' and if the Dictionary contains the key == id, we simply sea...
Hi, I have some example data:
public struct Task
{
public int INT;
public string STRING;
public DateTime? NULLABLEDATETIME;
}
And function, which uses it:
public KeyValuePair<Expression<Func<Task, object>>, object> Marry(Expression<Func<Task, object>> key, object value)
{
return new KeyValuePair<Expression<Func<Task, ...
I'm attempting to pass a generic list of integers from a client application to a web service using the the SOAP protocol.
When I attempt to pass the list as a parameter to the web method declared in the web service, I get the error "cannot convert from generic.list to ArrayOfInt".
How do I go about resolving this?
// web service metho...
Hi,I want to build a form entity, which should contain form form fields
so: i want to have a class that looks something like this:
public abstract class form {
public string FormName;
public IList<FormField> Fields;
}
i want my FormField class to have one method: getValue.
But, i want it to be generic, so getValue would not return a...
I've tried two ways to constrain a generic type parameter to a nullable type, but both seem to have some unexpected problems.
First attempt (using T <: AnyRef):
scala> def testAnyRefConstraint[T <: AnyRef](option:Option[T]):T = {
| //without the cast, fails with compiler error:
| // "found: Null(null) required: T"
| o...
Hi
I have two classes
public class JobDataProvider
{
public List<Job> Get(int id){
List<Job> jobs = new List<Job>();
foreach(up_GetJobResult result in myDataContext.up_GetJob(id))
{
jobs.add(new Job(Id = result.Id, name = result.Name));
}
return jobs;
}
}//end class Job
public class Per...
Hi everyone, this is the first time I need to use generics and references and I'm having a difficult time of it. I know it's something obvious.
public class Program
{
void SWAP<T>(ref T a, ref T b) { T dum = a; a = b; b = dum; }
static void Main(string[] args)
{
double a = 1; double b = 2;
double c = SWAP(a,...
I have a class called Person:
Public Class Person
Private PersonID as String
Private Name as String
Private Records as GenericCollection(Of PublicRecord)
Public Sub New(ByVal ID as String)
Me.PersonID = ID
Me.Name = getPersonName(ID)
End Sub
'Get/Sets
End Class
getPersonName is simply a function ...
Hi all,
I seem to have a bit of misunderstanding with Java Generics and I hope you can help me. I tried to create a map like so:
Map<Debater, int>
(Debater is an Interface I declared) but java complained about the int, so I did:
Map<Debater, Integer>
I suppose it's because int is not a class while Integer is, is this correct?
Also...
Hi,
I'm wondering how to iterate over a List with mixed contents using foreach. See the example code below.
public class GenericsForeach {
class A {
void methodA() {
System.out.println(getClass().getSimpleName() + ": A");
}
}
class B extends A {
void methodB() {
System.out.p...
For example:
class MyClass<T extends MyClass2> {
// Do stuff...
}
Then later:
MyClass<MyClass2> myClass = new MyClass<MyClass2>();
Does this work? My coworker's hunch is no, but I can't find anything to confirm that for me and the documentation suggests perhaps.
...
I'm trying to use this method but I get an error in Eclipse saying the type argument is incorrect and it tells me to change the method signature. Any reason why?
/**Creates an independent copy(clone) of the T array.
* @param array The 2D array to be cloned.
* @return An independent 'deep' structure clone of the array.
*/
public stat...
Hello,
Here is my scenario:
We have a legacy system that has about 100 views that all pull the same columns worth of data.
Now, in my DataContext I have all the views in the context and I have a seperate query from each one. Each query's results loads into a single List that gets returned to the application.
Is it possible to have a s...
I would like make an extension method for the generic class A which takes yet another generictype (in this example TC), but i guess that aint possible?
class Program
{
static void Main(string[] args)
{
var a = new A<B, B>();
a.DoIt<B>();
}
}
static class Ext
{
public static A<TA, TB> DoIt<TA, TB, TC>(th...
There seems to be some debate over refactoring to utilize java generics within my current team. The question I have is what are the current industry standards in terms of refactoring older Java code to take advantage of some of these features? Of course by industry standards I am referring to best practices. A link to a book or a site...
I know why one shouldn't do that. But is there way to explain to a layman why this is not possible. You can explain this to a layman easily : Animal animal = new Dog();. A dog is a kind of animal but a list of dogs is not a list of animals.
...
I wrote this extension method:
public static DataTable ToDataTable<T>(this IList<T> list)
{...}
It works well if called with a type known at compile time:
DataTable tbl = new List<int>().ToDataTable();
But how to call it if the generic type isn't known?
object list = new List<int>();
...
tbl = Extension.ToDataTable((List<object>)l...
While compiling a program in Java I got this big WARNING
warning: [unchecked] unchecked call to
LinkedList(java.util.Collection) as a member of the raw
type java.util.LinkedList
on this line:
LinkedList<Integer> li2 = new LinkedList(li);
What does this warning mean?
Edit:
It should have been infact: LinkedList<Integer> li2...
In some library I create I have to use following cast:
public void Foo(IList<uint> uintsList) // I need to use uint in the interface for this method
{
List<double> doublesList = uintsList.Cast<double>().ToList();
// Do something with the doublesList
}
I assumed that cast uint -> double should be always valid, and during my tes...