如何将实际方法作为参数传递给Java中的另一个方法?(How can you pass in an actual method as a parameter to another method in Java?)
我想要做的是轻松地将实际的方法对象传递给另一个方法。 这样我就可以创建一个通用的Joiner函数,该函数连接对象列表的给定方法,而不会只传入表示该方法的字符串。 这在Java中是否可行,以便我可以使用以下语法:
joinOnMethod(String, Collections<T>, Method) e.g. joinOnMethod(", ", someList, T.getName())
其中T.getName()将getName()方法传递给列表中的每个对象,而不是传入方法本身的返回类型。
希望这足以满足我的需求,
阿列克谢蓝。
What I want to do is to easily pass in an actual method object to another method. This is so I can create a generic Joiner function that joins on a given method of a list of objects without the danger of just passing in a string that represents the method. Is this possible in Java so that I can have syntax like:
joinOnMethod(String, Collections<T>, Method) e.g. joinOnMethod(", ", someList, T.getName())
Where T.getName() passes the getName() method into be called on each object in the list instead of passing in the return type of the method itself.
Hope this is clear enough for my needs,
Alexei Blue.
原文:https://stackoverflow.com/questions/10653658
最满意答案
我从未使用链式提供程序,但文档显示配置看起来与您的不同:
security: providers: chain_provider: chain: providers: [in_memory, user_db] in_memory: memory: users: foo: { password: test } user_db: entity: { class: Acme\UserBundle\Entity\User, property: username }
I've never used chained providers but documentation shows that the config looks like different than yours:
security: providers: chain_provider: chain: providers: [in_memory, user_db] in_memory: memory: users: foo: { password: test } user_db: entity: { class: Acme\UserBundle\Entity\User, property: username }
相关问答
更多-
你需要这个提供,就像这个配置一样: jms_security_extra: secure_all_services: false expressions: true security: encoders: Symfony\Component\Security\Core\User\User: plaintext role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADM ...
-
我解决了这个问题......只需将user_provider:provider_name添加到配置中即可 I solved the problem ... it is quite simple just add user_provider: provider_name to the config
-
当我发布问题时,我被困住了,但是在睡了一觉之后就找到了答案;) 结果我很久以前就遇到过一个问题: https : //github.com/symfony/symfony/issues/4498 简而言之, 问题与配置无关。 它也不是认证。 它实际上与重定向后如何刷新经过身份验证的用户有关。 这就是为什么应用程序在重定向页面上被正确认证为“用户”的原因,但之后却没有。 这是框架刷新用户时的代码(可以在\ Symfony \ Component \ Security \ Http \ Firewall \ C ...
-
您的User实体实现UserInterface而不是UserProviderInterface EDITED 例外是: exception 'Symfony\Component\Security\Core\Exception\AuthenticationServiceException' 随着消息 'The Doctrine repository "My\UserBundle\Entity\AdminRepository" must implement UserProviderInterface.' in ...
-
Symfony2注销CSRF保护:csrf_provider无法识别(Symfony2 logout CSRF protection: csrf_provider unrecognized)[2022-06-17]
我研究了Symfony的代码并发现现在csrf_provider选项已重命名为csrf_token_generator 。 然后,我搜索了一下GitHub上的相关问题 。 所以这个问题在一个不同步的文档中。 最终的解决方案是: 组态: # app/config/security.yml security: # ... firewalls: # ... your_firewall_name: # ... logo ... -
我从未使用链式提供程序,但文档显示配置看起来与您的不同: security: providers: chain_provider: chain: providers: [in_memory, user_db] in_memory: memory: users: foo: { password: test } ...
-
我遇到了同样的问题,我正在添加答案,让其他人更容易看到。 如果你得到 没有为帐户“Symfony \ Component \ Security \ Core \ User \ User”链提供程序配置编码器 您需要添加如下所示的编码器(对于数据库用户和内存中的用户)[security.yml] security: encoders: Splendonia\Bundle\UserBundle\Entity\User: algorithm: sha512 ...
-
经过一些搜索和错误修复,我发现实现它的最简单方法是使用Regex,所以我改变了我的security.yml : api: pattern: ^/api/v\d+\.\d+/ provider: api_domain anonymous: false guard: authenticators: - app.token_authenticator lexik_jw ...
-
[ConfigurationProperty(“provider”)]做了什么?(what does [ConfigurationProperty(“providers”)] do?)[2022-05-27]
[Foo(bla)]是属性的语法 - 关于某个类型或成员的附加元数据(甚至是程序集本身;或者实际上是参数)。 您可以编写自己的属性,例如: public class ConfigurationPropertyAttribute : Attribute { public ConfigurationPropertyAttribute(string something) {...} } 推断名称Attribute ,因此只需要[ConfigurationProperty] 。 字符串"providers ... -
使用sha512编码器和symfony2 in_memory安全提供程序(using sha512 encoder with symfony2 in_memory security provider)[2022-04-05]
经过多次试验和错误,我能够工作的唯一配置是最简单的情况: security: encoders: Symfony\Component\Security\Core\User\User: algorithm: sha512 encode_as_base64: false iterations: 1 providers: in_memory: memory: ...