COMP 2210 Course Blog

Friday, January 29, 2010

Generic type warnings

Unless you've successfully completed the extra credit with generic types, you're getting compile-time warnings about type safety. If you use the -Xlint:unchecked compiler flag (see an earlier blog post), you'll get details about the warning but not much insight into why it's happening or how to fix it.

Why it's happening: The compiler can be sure that both target and a.get(i) on line 11 are both instances whose classes implement the Comparable interface, but there's no guarantee that they are mutually comparable. For example, target could be a Photo and a.get(i) could be a String. Both are Comparables, but they can't be compared to each other. So, the compiler gives you a warning.

What to do about it: Nothing. Ignore it. Unless you're trying to earn extra credit for making the SearchLibrary class generic, don't worry about these warnings. They're just warnings, after all, and they won't prevent your program from compiling and running. If you're trying for the extra credit, however, a successful generic implementation of SearchLibrary will eliminate the warnings (and earn you 10 extra points).

Thursday, January 28, 2010

ArrayList, indexOf() method

In Assignment 1 (#6a in particular), you are asked to write code that is essentially equivalent to the indexOf() method in java.util.ArrayList. Do not call this java.util.ArrayList.indexOf() method to do the work for you. You must write the search logic yourself. The assignment description has been updated to reflect this restriction. If you have any questions, just ask a TA or me.



Tuesday, January 26, 2010

Date class, deprecated methods

As some of you have noticed from compiler messages, java.util.Date has deprecated methods, including several of its constructors. The compiler will issue a warning when you try to use these methods, but this does not mean that there is an error. Using the Date class will not prevent your code from compiling or running.

Deprecation in Java is used to identify classes, methods, and interfaces that are "outdated" and should no longer be used. When something is deprecated, a suggested replacement is identified. For example, the API tells us that java.util.Calendar has the preferred functionality for the deprecated methods in Date. You can read more about deprecation in Java's online documentation.

In the context of this assignment, there are two things to realize about method deprecation in the Date class.

(1) The Date class will work just fine for you in this assignment. DO NOT USE THE CALENDAR CLASS. For what you have to do, the Date class is simple and sufficient.

(2) You can tell the compiler to give you more information about warnings like this. The default compiler warning tells you to recompile with the -Xlint:deprecated flag. You can do this from the command line or from within your IDE.
Here's screenshot from jGRASP where I've set two compiler flags "-Xlint:unchecked -Xlint:deprecated". Notice that the first flag (unchecked) has scrolled to the left. (The "unchecked" flag will give you lots of useful information about generic type usage.) You can access this dialog in jGRASP via Settings->Compiler Settings->Workspace.



A place for longer posts

As the course blog for COMP 2210, this will be a place where I can post longer announcements or give information that's not convenient for the announcements feed or the calendar. On some of the posts, I'll also allow you to comment so maybe the class can have a bit of a dialog on a subject.
__
dh