Developers who have used eclipse cannot miss out the Cntrl+Shift+G combo - the easiest way to find all references to a particular member/method/class in your workspace.
Consider a scenario where you are a new guy maintaining a web application written in java. Now, you are about to change a method signature, and you do a Cntl+Shift+G to ...
Given the following two interfaces (these are small examples, not my actual implementation):
public interface IAssertion<T> {
IAssertion<T> IsNotNull();
IAssertion<T> Evaluate(Predicate<T> predicate)
}
public interface IStringAssertion : IAssertion<string> {
IStringAssertion IsNotNullOrEmpty();
}
and a static factory t...
Hi guys,
I've defined a method in a class:
public void setCollection(Collection<MyClass>);
and in another class
public void setCollection(Collection<OtherClass>);
(and really, lots of similar classes)
All are in classes with the same superclass, and I have a method in a support-class where I want to call this method and set it wit...
In general I come across this a lot. Some of my co-workers prefer very simple, easy to read classes even if that means that there is some code duplication, whereas I do everything in my power to avoid code duplication, even if it means making more a complicated architecture. What is the best practice? I work exclusively in Java.
...
I have a Collection<T>. I have a class TManager implementing an interface UManager which has a method getCollection() that needs to return a Collection<U> where U is an interface, and T is a class that implements U.
Aside from just casting it, e.g. return (Collection<U>)Tcoll;, is there a more correct way to handle this?
I control all ...
Lets say I have a Node class as follows:
class Node<T>
{
T data;
List<Node<T>> children;
internal Node(T data)
{
this.data = data;
}
List<Node<T>> Children
{
get
{
if (children == null)
children = new ...
This gives me an error:
int[] l = new int[] {0, 2, 192, -1, 3, 9, 2, 2};
int[] l2 = new int[] {9001, 7, 21, 4, -3, 11, 10, 10};
int[] l3 = new int[] {5, 5, 5, 64, 21, 12, 13, 200};
Set<List<Integer>> lists = new HashSet<List<Integer>>();
lists.add(Arrays.asList(l));
Eclipse: The method add(List<Integer>) in the type Set<List<Inte...
The following gives me an error message:
public static List<Comparable<?>> merge(Set<List<Comparable<?>>> lists) {
List<Comparable<?>> result = new LinkedList<Comparable<?>>();
HashBiMap<List<Comparable<?>>, Integer> location = HashBiMap.create();
int totalSize;
for (List<Comparable<?>> l : lists) {
location.put(l, 0);
totalSiz...
I wrote this handy, generic function for converting a collection of collections into a single set:
public static <T> Set<T> makeSet(Collection<Collection<T>> a_collection) {
Iterator<Collection<T>> it = a_collection.iterator();
Set<T> result = new HashSet<T>();
while (it.hasNext()) {
result.addAll(it.next());
}
return result;
}
...
Hi,
I need to define a generic class, and the type parameter must be an enum. I think it should look something like
public class <T> MyClass<T extends Enum<T>> {
}
But I can't seem to figure out the exact syntax. I should mention that I need a way to refer to the type (within MyClass) that it is instantiated with.
Thanks!
...
I've got the following:
public abstract class Foo<T>{
//contents of Foo //
...
public class Bar<Q> extends Foo<T>{
//contents of Foo.Bar //
...
}
}
Later, in another class and java file, I am trying to construct an instance of the inner Bar class above, using the outer abstract class as a supertype. ...
Ok, this question is best explained in code. So will try to present the most succinct example I can.
Timestamped.java
@Embeddable
public class Timestamped<E> {
private E value;
private Date timestamp;
...
}
Foo.java
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
public class...
I wrote a class that has a map of <String, Object>. I need it to hold arbitrary objects, but at the same time sometimes I need to cast some of those objects, so I'll do something like
HashMap<String, Object> map = new HashMap<String, Object>();
Object foo =...
In the following WPF application, when you click the button, why does TheTitle TextBlock update but FilesCopied ListBox not update?
XAML:
<Window x:Class="TestList3433.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300...
Possible duplicates:
http://stackoverflow.com/questions/24692/where-can-you-find-fun-educational-programming-challenges
http://stackoverflow.com/questions/3088/best-ways-to-teach-a-beginner-to-program
http://stackoverflow.com/questions/6327/what-are-your-programming-exercises
etc...
Hello,
I like to learn new programming languages ...
public class Leaf : IComponent<Leaf>
{
//...
}
Does this type of generic inheritance mechanism have any specific name?
What is the benefit of this type of usage of Generics?
...
HashMap<String, int> doesn't seem to work but HashMap<String, Integer> does work.
Any ideas why?
...
I have a function that works great in C# that I'm converting to VB.Net. I'm having an issue converting the result set to a generic list in VB.net.
The code:
Public Function GetCategories() As List(Of Category)
Dim xmlDoc As XDocument = XDocument.Load("http://my_xml_api_url.com")
Dim categories = (From category In xmlDoc.Descendan...
I'm trying to write a generic cached property accessor like the following but am getting a compiler error when trying to check whether the storage variable already contains a value:
function TMyClass.GetProp<T>(var ADataValue: T; const ARetriever: TFunc<T>): T;
begin
if ADataValue = Default(T) then // <-- compiler error on this line
...
I have three classes; Stamp, Letter and Parcel that implement an interface IProduct and they also have some of their own functionality.
public interface IProduct
{
string Name { get; }
int Quantity { get; set; }
float Amount { get; }
}
public class Stamp : IProduct
{
public string Name { get { return "Stamp"; } }
...