这个 Java 代码片段的 Perl 等价物是什么? (Perl 术语的 Java 解释)
任何人都可以帮我将这个 java 片段“翻译”成 perl/Moose 术语吗?试图理解 java 对象语法/逻辑,但我只知道 perl。
根据评论进行编辑:该片段来自 xwiki 包 - http://platform .xwiki.org/xwiki/bin/view/DevGuide/WritingComponents... 它太大了,无法分析,那么剩下的代码呢?是可能的(仅用于解释 - 忽略@lines?'@something'的一般含义是什么?
@Component("hello")
public class HelloWorldScriptService implements ScriptService
{
@Requirement
private HelloWorld helloWorld;
public String greet()
{
return this.helloWorld.sayHello();
}
}
寻找类似下一个perl片段的东西,但不知道“@Component,@Requirement - 等:(
package HelloWorldScriptService;
use Moose;
sub greet {
return $self->
}
存在一些文档用 perl 式的术语解释了 java(至少是一些基础知识)
Can anybody help me "translate" this java snippet into perl/Moose terms?. Trying understand java object-syntax/logic and I know only perl.
EDIT based on comments: The snippet is coming form the xwiki package - http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents...
It is too big for analyze, so what about the remaining of the code? Is possible (for the explanation only - ignore the @lines? What is the general meaning of the '@something'?
@Component("hello")
public class HelloWorldScriptService implements ScriptService
{
@Requirement
private HelloWorld helloWorld;
public String greet()
{
return this.helloWorld.sayHello();
}
}
Looking for something like the next perl fragment, but have no idea about "@Component, @Requirement - etc :(
package HelloWorldScriptService;
use Moose;
sub greet {
return $self->
}
Exists some docs where java is explained with perl-ish terms? (at least, some basics)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定 @Component,但这里有更多信息:
由于 helloWorld 是原始属性中的私有属性,因此您可能需要在名称“hello_world”前添加下划线(并添加 init_args => undef) - 这不会强制执行像 Java 一样的隐私,但确实向查看代码的任何人表明它在概念上是私有的(并阻止在 new() 上进行设置)
not sure about the @Component, but here's some more:
since helloWorld is a private attribute in the original, you might want to prepend the name 'hello_world' with an underscore (and add init_args => undef) - this doesn't enforce privacy like Java but does show to anyone looking at the code that it's conceptually private (and prevents setting on new())
这些注释是某些 依赖注入 框架的元数据(看起来 XWiki 使用自己的依赖注入支持,并且这些注释被它使用)。
当此类单独使用时,它们没有任何特殊含义。但是当在 DI 容器中使用时,
@Requirement
表示helloWorld
的值要由容器注入,@Component
表示类本身可以注入到其他组件中。These annotations are metadata for some Dependency Injection framework (it looks like XWiki uses its own dependency injection support, and these annotations are used by it).
When this class is used on its own, they don't have any particular meaning. But when it's used inside a DI container,
@Requirement
indicates that the value ofhelloWorld
is to be injected by the container, and@Component
indicates that the class itself can be injected into other components.