Why class implementing NamespaceContext compiles in Java 6, but notJava 5?

D

david.karr

I have a class that implements javax.xml.namespace.NamespaceContext.
As far as I can tell, this interface has not changed between Java 5
and Java 6 (specifically 1.5.0_11 and 1.6.0_07). My class implements
the three methods of the interface, and puts the "@override"
annotation on each one of them.

When I compile this class with Java 6, either from within eclipse or
standalone, it compiles and runs fine. When I compile it with Java 5
(eclipse and standalone), it complains "method does not override a
method from its superclass", for all three interface methods. What am
I missing here?

Here's the class:
-----------------------
package xpathfind;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.xml.namespace.NamespaceContext;

public class MapNamespaceContext implements NamespaceContext
{
private Map<String, String> uriMap = new HashMap<String,
String>();
private Map<String, String> prefixMap = new HashMap<String,
String>();

public MapNamespaceContext(Map<String, String> uriMap)
{
this.uriMap = uriMap;

for (String key: uriMap.keySet())
prefixMap.put(uriMap.get(key), key);
}

public MapNamespaceContext(String[] colonPairs)
{
uriMap = new HashMap<String, String>();

for (String colonPair: colonPairs)
{
int colonIndex = colonPair.indexOf(':');
uriMap.put(colonPair.substring(0, colonIndex).trim(),
colonPair.substring(colonIndex + 1));
}

for (String key: uriMap.keySet())
prefixMap.put(uriMap.get(key), key);
}

@Override
public String getNamespaceURI(String prefix)
{
return (uriMap.get(prefix));
}

@Override
public String getPrefix(String namespaceURI)
{
return (prefixMap.get(namespaceURI));
}

@Override
public Iterator getPrefixes(String namespaceURI)
{
return (null);
}
}
-------------
 
D

david.karr

AIUI, in Java 5 @Override only applied when the class extended a superclass,
not when it directly implemented an interface.  This was changed for Java 6.



That Java 6 does not conform to this is apparently an error, unless there's an
addendum I haven't found yet.

Got it. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top