简体   繁体   English

如何在Smalltalk中打印作为参数发送给类方法的字符串

[英]How to print a string that is sent as a parameter to class method in smalltalk

I'm trying to write a class method which recieves a string and prints it. 我试图写一个接收字符串并打印它的类方法。 I've tried this: 我已经试过了:

log: aMessage
Transcript show: aMessage; cr.

and tried to use it as follows: 并尝试如下使用它:

ContractObject log: 'aaa'.

(ContractObject is the name of class) but it didn't work. (ContractObject是类的名称),但是没有用。 I'm assuming it has something to do with the fact that it's a dynamic language and that it's not known that it's a string. 我假设它与以下事实有关:它是一种动态语言,并且不知道它是一个字符串。 I tried to convert it etc. Nothing worked. 我试图将其转换,等等。

No, types are definitely not the problem here. 不,类型绝对不是这里的问题。 What do you mean by "it didn't work"? 您所说的“无效”是什么意思? What was the error message you got? 您收到的错误消息是什么? Did you get any at all? 你有没有得到任何东西?

Do you have the Transcript open? 您有成绩单吗? If it's not open you wont see anything. 如果没有打开,您将看不到任何东西。 You can open it programmatically by evaluating Transcript open or manually by using the menu. 您可以通过评估“ Transcript open编程方式打开它,也可以使用菜单手动打开它。

Also, make sure that you have implemented #log: on the class side (that's what you see when you click the class button in the code browser). 另外,请确保已在类方面实现了#log:这是您在代码浏览器中单击class按钮时看到的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM