In Java, is it possible to declare a field/variable whose type is multiple interfaces? For example, I need to declare a Map that is also Serializable. I want to make sure ... |
This is a real beginner question (I'm still learning the Java basics).
I can (sort of) understand why methods would return a List<String> rather than an ArrayList<String>, or why they would accept ... |
Let's say I have the following Java interface that I may not modify:
public interface MyInterface {
public void doSomething();
}
And now the class implementing it is like this:
class MyImplementation implements MyInterface ...
|
Big class contains Format-interfcase and Format-class. The Format-class contains the methods and the interface has the values of the fields. I could have the fields in the class Format but the ... |
I have an interface that declares set() method.
One implementing class operates on byte[] arrays, therefore it will implement set(byte[] arr)
Another class operates on int[] arrays, therefore it will implement set(int [] ... |
Which of the following is correct when writing a method that returns an arrayList of cats.
public List getCatsByCatHerderID(int id);
public ArrayList<Cat> getCatsByCatHerderID(int id);
public List<Cat> getCatsByCatHerderID(int id);
|
This is closely related to, but is not the same question as: Method name collision in interface implementation - Java
When there are two Java interfaces that share a method with ... |
|
I've searched for a potential answer to my question below, and have not found one.
I understand the difference between checked and unchecked exceptions as well as what the programmer can/must do ... |
I've been doing some sax parsing in Java recently. I noticed the initialization for namespace mappings
private Map<String,String> namespaceMappings = new HashMap<String,String>();
my question is why we create a Map variable instead ... |
I have what I thought was a framework that would allow me to create a client/server application where the server could either reside remotely or operate locally, as part of the client component. I created the following classes and interfaces to accomodate local and remote access to the server: public interface Service { public List search(String[] criteria) throws ServiceException; public void ... |
Why does this not compile? //interface1.java; compile with javac interface1.java; run with java DoerTest interface Doer { public String do(); } class ADoer implements Doer { public String do() { return "A"; }; } class BDoer implements Doer { public String do() { return "B"; }; } class DoerTest { public static void main(String args[]) { Doer adoer = new ADoer(); ... |
I've got an interface that represents objects that you can obtain characters from. I have 2 implementations of this interface. The first one wraps a Java String, and the second one wraps a text file. The method on the interface used to obtain the character is readCharacter(). I don't need to declare a possible exception for the String implementation, but I ... |
|
I think I understand, but as always, I reserve the right to be wrong. An ArrayList is the 'Resizable-array implementation of the List interface' Since the ArrayList class implement the List interface, all of the List Methods are available to use. List is also abstract and cannot be instantiated by itself. ie: List lst = new List(); Array list also inherit ... |
I can poke a toothpick up my nose, but I don't need to do it. Just because the compiler allows it, there doesn't have to be a reason. At best it's useful if the interface defines a method that takes or provides an instance of an implementation of this inner interface, without needing to release it to a larger scope. Since ... |