22 Discussion / Question Topics
Remove Filter
|
|
Hello all I am using Generics in Java to perform some arithmetic operations, but I am getting some error **The operator + is undefined for the argument type(s) T, T** here is my code package com.genericsexample; public class GenericsArithmetic<T> { private T number1, number2,sum,product,difference; public void AddNumbers(T number1, T number2){ … |
|
hi,I have a classB which is in location "test\folder1\generics1" and Class2 which is generic class in another folder for eg test\folder2\ and when i create object for class2 which should be able to acces class1 method which is MethodA() please advise.Thanks in advance namespace generics1 { public class B { … |
|
public class SongIterator<T,L> implements Iterator<Song<T, L>> {} |
|
Suppose I have the following generic classes; Queue<T> KellysCoffee CheckOut and the following generic interfaces QueueInterface OrderLineInterface Suppose I want `KellysCoffee` to extend Queue class and implement `OrderLineInterface` This is how I've done it private class KellyCoffee<Order extends Queue<Order>> implements OrderLineInterface{} Now when I try to implement `CheckOut` public class … |
|
would you just do @Override public boolean contains(T param){ return hashTable[function(param)]!=null; } |
|
I'm having trouble pinpointing the exact definition of a generic linkedstack class Suppose I have public class LinkedStack<T> { //some variables //would this be right LinkedStack(){ } //for a generic constructor of type T for the LinkedStack class of type T? } |
|
Hi everyone, we were taught about Generics and Interfaces at uni and I wasn't sure what the perfect situations are to use interfaces because they don't have implementation in them so they work as a contract to other classes where everyone can implement their methods as long as they extend … |
|
public class GenericDemo<E extends GenericDemo> { E innerE; public E doStuff(E e, GenericDemo<E> e2) { //insert code here } public E getE() { return innerE; } } The options are: 1. return e 2. return e2.getE() 3. return e2 4. return e.getE() Option (1) and (2) compile fine. Option (3) … |
|
import java.util.*; public class GenericDemo4 { public static void main(String r[]) { Set s1 = new HashSet(); s1.add(0); s1.add("1"); dostuff(s1); } static void dostuff(Set<Number> s) { do2(s); Iterator i = s.iterator(); while(i.hasNext()) System.out.println(i.next() + " "); Object [] oa = s.toArray(); for(int x = 0; x<oa.length; x++) System.out.println(oa[x] + " … |
|
import java.util.*; class SampleA { } class SampleB extends SampleA{ } class SampleC extends SampleA{ } class VectorDemo { public static void main(String r[]) { Vector<SampleA> v = new Vector<SampleA>(); v.add(new SampleB()); v.add(new SampleC()); SampleC rect = v.get(2); } } The output says "Incompatible types. Found SampleA, required SampleC. SampleC … |
|
Hello all, been a while since I've asked a question. I'm working on a project just to practice and for fun and I've run into a snag. I'm working on a painting type program and I'm trying to get a generic Buffer class for the images so I can use … |
|
Related to: C#; Windows form, Storing Multiple Instances of a User Control: Hi: I’ve created an app with a user control that accepts parameters. When a user clicks a button I need to store the current view of the control and bring into focus on demand. Several instances of the … |
|
Hellow. I have 3 variables 1. string query; 2. public static OracleCommand oracmd; 3. public static OracleDataReader reader; I have used these variables in a function [CODE=C#] . . . public void PreviousValue() { query = " select * from....... "; oracmd = new OracleCommand(); .... .... reader = oracmd.ExecuteReader(); … |
|
The sort methods for collections specifies that the parameter must be a collection of objects that implement Comparable for their own class or superclass, eg [CODE]public static <T extends Comparable<? super T>> void sort(List<T> list)[/CODE] Can anyone tell me how to define an ArrayList that will only accept such objects? … |
|
I have a problem with this construction, can not find how to rewrite it properly. [CODE] private SqlParameter op <T> (T? t, string name) { SqlParameter sp = new SqlParameter(); sp.IsNullable = true; sp.ParameterName = name; sp.Value = t.HasValue ? t.Value : Convert.DBNull; return sp; } [/CODE] |
|
I'm trying to create a class that reads in a set of numbers from a file, stores them in a generic array, and then sorts them using the generic bubbleSort method. I usually write in C++ and the switch from templates to generics hasn't been easy. I'm fairly certain my … |
|
I can understand that the subtype covariance relation should not hold for parameterized types, but why should it hold for arrays ? One of the books (Khalid Moghul) said [QUOTE]This relation holds for arrays because the element type is available at runtime[/QUOTE] How does the element type being available at … |
|
Hello. It's been a while since I was on here. I'm writing a Java class with a generic type parameter. Among other things, it maintains an internal ArrayList of the same generic type as itself. In a perfect world, the code would go like this: [CODE=Java]import java.util.ArrayList; public class MyGenericClass<T> … |
|
I'm creating a system that has a parameterized class "TypeModule<T>". Now, I have another class that has the following member; [CODE]private LinkedHashMap<Class, ArrayList<TypeModule>> m_modules = ...[/CODE] Here's my dilemma. I need something more like the following; [CODE]private LinkedHashMap<Class<?>, ArrayList<TypeModule<?>>> m_modules = ...[/CODE] The only thing is, I need the '?'s … |
|
|
Hi all, to simplify my problem, I'll use a quick example. Imagine I have a class of 'Cat' which has accessors for things like 'name', 'colour' and 'height'. I then put these cats in a list [CODE]List<Cat^>^ catList;[/CODE] I want to be able to search this list based on the … |
Hi, I am working on assignments that deal with Generics in java. I have a class Movie that have a String name variable. However I have to add a few more properties to Movie objects like Release year and Director name. So I created an Inventory class that uses the … |
|
|
I am getting the message when i start the computer that Generic Host Process for Win32 Services Error. I have seen the advanced options/details of the message and it is as under: szAppName : svchost.exe szAppVer : 5.1.2600.2055 szModName : wiaservc.dll szModVer : 5.1.2600.2055 offset : 00017f81 Please help me … |
The End.