Can a class accept a message?

D

Daniel Pitts

tenxian said:
I want a confirmation.
That is a very vague question. So the answer is Yes.

public class Message {
}

public class MessageAcceptor {
public static void accept(Message message) {
System.out.println("I accept the message " + message);
}
}

So, what are you really asking?
 
M

Mark Space

tenxian said:
I want a confirmation.

This kind of statement comes across as bit rude. Please use a less
demanding tone.


In Java, classes can accept messages, for reasonable definitions of the
word "message".

String.getClass().getName();

sends the message "getName" to the class object for String. One could
also call static methods a message that a class will accept.

Normally however, it's an object that takes the message.

String s = "Hello World\n";
s = s.trim();

sends the message "trim" to the String object "s".


(In object oriented design that I'm familiar with, a "message" is
normally implemented with a method. Other forms of dispatch might
exist, although I can't think of any off the top of my head.)
 
R

Roedy Green

I want a confirmation.

I presume you mean this is the Smalltalk sense.

Of course. All it means is can your execute a method on an object
with parameters.
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top