Hi,
I'm working on the exception handling layer for my application.
I have read few articles on interfaces and generics. I have used inheritance before quite a lot and I'm comfortable with in that area.
I have a very brief design that I'm going to implement:
public interface IMyExceptionLogger
{
public void LogException();
// ...
Just came across a place where I'd like to use generics and I'm not sure how to make it work the way I want.
I have a method in my data layer that does a query and returns a list of objects. Here's the signature.
public List getList(Class cls, Map query)
This is what I'd like the calling code to look like.
List<Whatever> list = get...
I tried to make sure this wasn't a duplicate post, sorry if I was blind.
This is a small snippet of code taken from some of the examples that accompany the Stanford Parser. I've been developing in Java for about 4 years, but have never had a very strong understanding of what this style of code is supposed to indicate.
List<? e...
Hi,
I make a list in my code like so:
List<IConnection> connections = new List<IConnection>();
where IConnection is my own interface. This is in a .NET 2.0 executable. If I run the code on my machine (with lots of .Net versions installed) it works fine. If I run it on my test machine (which only has .NET 3.5 SP1 installed) then I get...
I'm using the Generics Collection library C5 (server down :-( ) and I have an IntervalHeap(T) and I need to Delete or Replace a T that is not the Max or Min. How do I get an IPriorityQueueHandle from my T? The C5 library source code shows that IPriorityQueueHandle(T) has no methods or properties to implement and the compiler thinks my im...
What is the syntax for explicitly giving the type parameters for a generic Java method?
...
Hi all, I'm new to Java. While coding a Map<>, I found out that declaring Map<int, int> is a syntax error while Map<Integer, Integer> is OK. Is it only possible in Java to instantiate generics over object types, as opposed to primitives? If so, is there a noticeable performance penalty for boxing/unboxing of primitives?
...
Hi!
I hope the title doesn't sound too subjective; I absolutely do not mean to start a debate on OO in general. I'd merely like to discuss the basic pros and cons for different ways of solving the following sort of problem.
Let's take this minimal example: you want to express an abstract datatype T with functions that may take T as inp...
I want to define the following class as such:
public class CollectionAttribute<E extends Collection<T>> {
private String name;
private E value;
public CollectionAttribute(String name, E value) {
this.name = name;
this.value = value;
}
public E getValue() { return value; }
public void addValue(T ...
So I have 3 classes.
Abstract class A
Class B extends class A
independent Class C
In class D that contains the main method, I create a list of instances of class B
List<B> b = methodCall(); // the method returns a list of instances of class B
Now in class C I have one method that is common to both A and B, and hence I don't wa...
Hi,
I'm hoping somebody can help me with this, I'm trying to write the mapping classes for a class that is subclassed into a generic class. Its easier to descibe with code, so here is my model...
public abstract class TagBase
{
public virtual int Id { get; private set; }
public virtual TagTypeEnum TagType { get; set; }
publ...
We use JUnit 3 at work and there is no ExpectedException annotation. I wanted to add a utility to our code to wrap this:
try {
someCode();
fail("some error message");
} catch (SomeSpecificExceptionType ex) {
}
So I tried this:
public static class ExpectedExceptionUtility {
public static <T extends Exception> void check...
What is the best procedure for storing and retrieving, using native Java serialization, generic objects like ArrayList<String>?
Edit: To clarify. When I serialize an object of type ArrayList<String> I'd like to de-serialize to the same type of object. However, I know of no way to cast back to this generic object without causing warni...
Is it possible to implement IXmlSerializable and in my XML file capture an object of type Dictionary> ?
I have the following
public class coolio : IXmlSerializable
{
private int a;
private bool b;
private string c;
private Dictionary<string, List<string>> coco;
public coolio(int _a, bool _b, string _c, Dictionary<string, List<string>>...
Given an generic interface like
interface DomainObjectDAO<T>
{
T newInstance();
add(T t);
remove(T t);
T findById(int id);
// etc...
}
I'd like to create a subinterface that specifies the type parameter:
interface CustomerDAO extends DomainObjectDAO<Customer>
{
// customer-specific queries - incidental....
My question is not easy to explain using words, fortunately it's not too difficult to demonstrate. So, bear with me:
public interface Command<R>
{
public R execute();//parameter R is the type of object that will be returned as the result of the execution of this command
}
public abstract class BasicCommand<R> implements Command<R>
...
More than a question, per se, this is an attempt to compare notes
with other people. I wrote a generic History class that emulates
the functionality of a browser's history. I am trying to wrap my
head around how far to go when writing unit tests for it. I am
using NUnit. Please share your testing approaches below.
The full code for the ...
I would like to know if (and if so how) it is possible to define a namespace as a constraint parameter in a generic class declaration.
What I have is this:
namespace MyProject.Models.Entities <-- Contains my classes to be persisted in db
namespace MyProject.Tests.BaseTest <-- Obvious i think
Now the decleration of my 'BaseTest' cla...
I have the following class
public class MyClass<T> {
public Class<T> getDomainClass() {
GET THE CLASS OF T
}
}
I've googled this problem and all the answers I could find told me to use getGenericSuperClass(), but the problem of this method is that I must have a second class that extends MyClass and I don't want to do...
In Java, assume I have the following class Container that contains a list of class Items:
public class Container<T>
{
private List<Item<? extends T>> items;
private T value;
public Container(T value)
{
this.value = value;
}
public void addItem(Item<? extends T> ite...