Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Java, Java 7 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java, Java 7 Edition by Ivor Horton ; ISBN: 978-0-470-40414-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Java, Java 7 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2012, 04:46 PM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up parameterized methodes

Chapter 13: Section Parameterized Methodes: Page 507-509

The author changes some methodes in the BinaryTree class to parameterized methodes in order to be able to add objects that are of types that are subclasses of a type parameter.

I don't understand what that is good for. The methodes also excepted types, which are subclasses of the type parameter supplied to the class befor making this change. The code seems to compile and run in the same way before and after the change. I put some code fragments below.

code before the parameterization of the methodes:
Code:
public class BinaryTree<T extends Comparable<? super T>> {
   ...
   public void add(T value) {
      ...
   }

   public void add(T value, Node node) {
      ...
   }
   ...
}
code after the parameterization of the methodes:
Code:
public class BinaryTree<T extends Comparable<? super T>> {
   ...
   public <E extends T> void add(E value) {
      ...
   }

   public <E extends T> void add(E value, Node node) {
      ...
   }
   ...
}

What is the diffrence between this two codes? Can't I supplement T with a subclass of T anyway? Don't they work exactly in the same way?
 
Old August 26th, 2012, 11:45 AM
Registered User
 
Join Date: Aug 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found an answer somewhere else. It seems like there is no difference in this code fragments. I either missunderstand the book, or it is mistaken.

Answer:
http://stackoverflow.com/questions/1...ric-class-type





Similar Threads
Thread Thread Starter Forum Replies Last Post
parameterized if-then not working hoqenishy XSLT 1 April 17th, 2008 01:25 PM
Parameterized Property surendraparashar C# 2005 4 October 17th, 2007 11:33 PM
Parameterized Query asters VB.NET 2002/2003 Basics 5 July 9th, 2007 12:08 PM
Document() ... parameterized ? asearle XSLT 18 October 4th, 2006 02:46 AM
Parameterized SQLDataAdapter boyshey VB.NET 2002/2003 Basics 1 April 14th, 2006 07:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.