Archive for May, 2005

Eclipse 3.1 M6 and Generics

Thursday, May 5th, 2005

The Eclipse compiler seems to choke on the following code, which is some generics-related issue. Consider the following:

private Set<ActionState> stateHistory = new TreeSet<ActionState>();

Now, I know a TreeSet will be stored in natural ascending order, but just consider the case where you might try to do this:

@Transient
public ActionState getCurrentState() {
if (stateHistory == null || stateHistory.size() == 0) {
return null;
}
return Collections.max(stateHistory);
}

Eclipse chokes with the error:


Bound mismatch: The generic method max(Collection< ? extends T>) of type Collections is not
applicable for the arguments (Collection< ? extends ActionState>) since the type ActionState is not
a valid substitute for the bounded parameter >

This is confusing, as ActionState implements Comparable.

If I change the offending line to read:

return ((TreeSet<ActionState>)stateHistory).last();

It works fine. It looks like it may be a bug in Eclipse’s compiler, as colleagues using IntelliJ IDEA have no such problems.

Log4j XML Configuration

Wednesday, May 4th, 2005

For some reason, I can’t seem to retain a key piece of information - how to configure the logging level per-package in the log4j XML configuration. I’m putting this snippet here to cater for the likely event that I’ll forget it again. It’s all to do with the category element, as it happens.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.SimpleLayout"/>
  </appender>

  <category name="org.apache">
        <priority value="warn"/>
  </category>

  <root>
    <priority value="debug" />
    <appender-ref ref="ConsoleAppender"/>
  </root>

</log4j:configuration>