473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

constrained type parameters

oll3i
679 512MB
cd u give me the example of constrained type parameters
Mar 15 '07 #1
4 1412
oll3i
679 512MB
is it something like
Expand|Select|Wrap|Line Numbers
  1. import java.util.List;
  2. import java.util.ArrayList;
  3.  
  4. public class Library<E extends Media> {
  5.     private List<E> resources = new ArrayList<E>();
  6.     public void addMedia(E x) {
  7.         resources.add(x);
  8.     }
  9.     public E retrieveLast() {
  10.         int size = resources.size();
  11.         if (size > 0) {
  12.             return resources.get(size - 1);
  13.         }
  14.         return null;
  15.     }
  16. }
  17.  
Mar 15 '07 #2
oll3i
679 512MB
or sth like this
Expand|Select|Wrap|Line Numbers
  1. int myProperty;
  2.     public int getMyProperty() {
  3.         return myProperty;
  4.     }
  5.     public void setMyProperty(int newValue) throws PropertyVetoException {
  6.         try {
  7.             vceListeners.fireVetoableChange(
  8.                 "myProperty", new Integer(myProperty), new Integer(newValue));
  9.             myProperty = newValue;
  10.         } catch (PropertyVetoException e) {
  11.             throw e;
  12.         }
  13.     }
  14.  
  15.     // Create the listener list.
  16.     VetoableChangeSupport vceListeners = new VetoableChangeSupport(this);
  17.  
  18.     // The listener list wrapper methods.
  19.     public synchronized void addVetoableChangeListener(VetoableChangeListener listener) {
  20.         vceListeners.addVetoableChangeListener(listener);
  21.     }
  22.     public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) {
  23.         vceListeners.removeVetoableChangeListener(listener);
  24.     }
  25.  
  26.  
Mar 15 '07 #3
oll3i
679 512MB
how to do it with ArrayList<String>
Mar 15 '07 #4
r035198x
13,262 8TB
cd u give me the example of constrained type parameters
If you want to restrict a collection to store object of type E only then you declare as

Expand|Select|Wrap|Line Numbers
  1.  ArrayList<E> list = new ArrayList<E>();
Mar 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ed Trubia | last post by:
Have the following type that applies contraints. How could this be easily coded in Java type ET_ACTIVE_PORT_CONFIGURATION is ( HDX_TX1_RX1, HDX_TX2_RX2, HDX_TX1_RX2, HDX_TX2_RX1,...
2
by: Jason Cartwright | last post by:
I have an abstract base class and two derived classes that I want to serialize and deserialize with schema validation. When I serialize instances of the derived classes the XmlSerializer adds the...
7
by: Leicester B. Ford Jr. | last post by:
I have this class: public class ItemType .... public class ProductType<T> where T: ItemType .... Now I want to add an IDisposable interface to ProductType...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
19
by: Fernando Cacciola | last post by:
I'm puzzled, Why and how _exactly_ is this: void Foo<T>(T v ) where T : Interface/Value/Class/class any better than this void Foo( Interface/Value/Class/object v )
7
by: laniik | last post by:
Hi, I am looking for a way to do nonlinear minimization in c++ (c is acceptable also) with constraints (a la minimize f() with parameters x,y such that x+y<1) or somthing.. I was wondering if...
1
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
6
by: Explore_Imagination | last post by:
The task is to solve a constrained optimization problem in C/C++. Computational Time is of high priority. One approach can be to use ready functions in a "free ware" Optimization Library (if...
2
by: Explore_Imagination | last post by:
The task is to solve a constrained optimization problem in C. Computational Time is of high priority. One approach can be to use ready functions in a "free ware" Optimization Library (if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.