Aug 04

This post is also available in: German

As we already know there is no problem in assigning different Collections on the base-object:

List <Integer> a= new ArrayList<Integer>();

It seem to be clear, that it should work with object-types in the same way, but this is not the case:

import java.util.List;
import java.util.ArrayList;
class Employee{

public static void main(String args[])

List <Employee> b = new ArrayList <SalesPerson>(); // CompilerError
SalesPerson a = new SalesPerson();


class SalesPerson extends Employee{ }

The rule behind is quite easy: declaration of types and transfer need to match exactly, although it is different for arrays;

Employee [ ] c = new SalesPerson[3]; is working without problems – so don’t get confused during certification :)

  • Print
  • Facebook
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • RSS
  • Blogosphere
  • email
  • PDF
  • Wikio
  • Technorati
  • Digg
  • DZone

Leave a Reply

preload preload preload Blog Top Liste - by Blogverzeichnis - Blog Verzeichnis Software
Webbhotell Top Blogs