22 Discussion / Question Topics

Remove Filter
Member Avatar for
Member Avatar for Varunkrishna

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){ …

Member Avatar for ~s.o.s~
0
10K
Member Avatar for kamilacbe

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 { …

Member Avatar for AleMonteiro
0
172
Member Avatar for Pyler
Member Avatar for Pyler

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 …

Member Avatar for Pyler
0
294
Member Avatar for Pyler

would you just do @Override public boolean contains(T param){ return hashTable[function(param)]!=null; }

Member Avatar for JamesCherrill
0
214
Member Avatar for Pyler

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? }

Member Avatar for JamesCherrill
0
129
Member Avatar for rotten69

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 …

Member Avatar for Ketsuekiame
0
158
Member Avatar for rahul.ch

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) …

Member Avatar for ~s.o.s~
0
246
Member Avatar for rahul.ch

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] + " …

Member Avatar for rahul.ch
0
299
Member Avatar for rahul.ch

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 …

Member Avatar for rahul.ch
0
225
Member Avatar for sciwizeh

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 …

Member Avatar for sciwizeh
0
2K
Member Avatar for ventura1

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 …

Member Avatar for ventura1
0
256
Member Avatar for six_sic6

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(); …

Member Avatar for six_sic6
0
188
Member Avatar for JamesCherrill

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? …

Member Avatar for ~s.o.s~
0
183
Member Avatar for VIeditorlover

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]

Member Avatar for gusano79
0
214
Member Avatar for JGriffCS

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 …

Member Avatar for JamesCherrill
0
694
Member Avatar for daudiam

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 …

Member Avatar for daudiam
0
169
Member Avatar for JDCyrus

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> …

Member Avatar for JDCyrus
0
181
Member Avatar for lee.j.baxter

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 …

Member Avatar for apines
0
121
Member Avatar for Smithy566

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 …

Member Avatar for Ancient Dragon
0
1K
Member Avatar for stevebush

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 …

Member Avatar for JamesCherrill
0
104
Member Avatar for kirtan_thakkar

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 …

Member Avatar for kirtan_thakkar
0
125

The End.