类类型的变量参数 - Java(Variadic Parameter of Class Types - Java)
以下面的方法为例。
<T extends MyInterface> void myFunction(Class<T>... types) { // Do some stuff that requires T to implement MyInterface }
现在,假设下面的方法调用假设
MyClass1
和MyClass2
都实现了MyInterface
。myFunction(MyClass1.class, MyClass2.class)
我收到以下错误。
不兼容的等式约束:MyClass1和MyClass2
我如何完成这项工作? 更具体地说,如何使用在Java中实现接口的类类型的可变参数?
Take for instance, the method below.
<T extends MyInterface> void myFunction(Class<T>... types) { // Do some stuff that requires T to implement MyInterface }
Now, given the method call below assuming
MyClass1
andMyClass2
both implementMyInterface
.myFunction(MyClass1.class, MyClass2.class)
I get the following error.
Incompatible equality constraint: MyClass1 and MyClass2
How do I make this work? More specifically, how would one use a variadic parameter of class types implementing an interface in Java?
原文:https://stackoverflow.com/questions/49418664
最满意答案
确保.authorizeRequests()块在.formLogin()之前出现(由@MosheArad建议)。 然后用'.successForwardUrl(“/”)'替换'.defaultSuccessUrl(“/ secure”)'。
根目录中有一个index.jsp,它优先于Controller中定义的映射。 删除此文件后,重定向开始起作用。
Ensure .authorizeRequests() block comes before .formLogin() (as suggested by @MosheArad). Then replace '.defaultSuccessUrl("/secure")' with '.successForwardUrl("/")'.
There was an index.jsp in the root directory, which was taking precedence over the mapping defined in Controller. After deleting this file the redirect started to work.
相关问答
更多-
如果没有,不工作(If not, not working)[2021-11-05]
你根本不需要那条线。 如果用户没有输入1,2或3,则直接进入Correct2。 你确定在其他比较中空间是否正常? 你可能想试试这个: :open set/p g=Choice: if "%g%"=="1" goto FNVEnd if "%g%"=="2" goto KSPEnd if "%g%"=="3" goto SKYPEEnd REM If we get here ... cls echo Welcome. timeout 3 goto Open You don't need that line ... -
确保.authorizeRequests()块在.formLogin()之前出现(由@MosheArad建议)。 然后用'.successForwardUrl(“/”)'替换'.defaultSuccessUrl(“/ secure”)'。 根目录中有一个index.jsp,它优先于Controller中定义的映射。 删除此文件后,重定向开始起作用。 Ensure .authorizeRequests() block comes before .formLogin() (as suggested by @M ...
-
这就像将fullyAuthenticated()更改为authenticated()一样简单。 正如在fullAuthenticated()的javadocs中所说: 指定经过身份验证且未“记住”的用户允许使用URL。 This is as simple as changing fullyAuthenticated() to authenticated(). As in javadocs for fullyAuthenticated() it is said : Specify that URLs are ...
-
Spring身份验证处理ajax请求和默认登录页面(Spring authentication handling ajax request and default login page)[2023-09-23]
也许你应该为它编写控制器? @Controller public class Controller { @RequestMapping(value = "getFrontPage.html", method = RequestMethod.GET) public String accesssDenied(Principal user) { return "getFrontPage.html"; } } 你也应该查看这篇文章 。 Okay, I found a so ... -
发现问题。 它不是与WebSecurityConfig的映射WebSecurityConfig 。 使用.failureForwardUrl()方法会发生奇怪的事情。 这是我发现的: 以下内容无法完全运行,导致我看到的错误 .formLogin() .loginPage("/login") .loginProcessingUrl("/loginProcess") .successForwardUrl("/admin") .failureForwardUrl("/login") ...
-
尝试这个 $postcode_extract->orWhereIn($column, $values) 此外,如果这不起作用,请尝试将第一个条件whereIn ,其余条件whereIn orWhereIn Oh this is so frustratingly obvious I think I might cry... foreach ($input as $column => $values) { $postcode_extract = $postcode_extract->orWhe ...
-
否则,如果不工作(Else if not working)[2022-12-15]
Length大于2的总是大于5因此如果语句块始终处于第一位。 if可以执行else部分,则首先更改条件。 if (length >= 2 && length <= 5){ console.log('more than two and less than five'); } else if (length > 5){ console.log('more than five'); } else{ console.log('single item'); } Lengt ... -
$(本).addClass(“为什么-你-没有工作”);($(this).addClass('why-you-no-working'); not working on waypoint?)[2023-07-01]
在这种情况下, this不涉及DOMElement 。 你可以通过属性this.element获得对DOMElement引用,在回调中 $('.parallax:nth-of-type(2)').waypoint(function() { $(this.element).addClass('why-you-no-working'); },{offset: '1%'}); 例 In this case this does not refer to DOMElement. You c ... -
为什么()不工作?(why is on() not working?)[2022-11-04]
您使用的是什么版本的jQuery,on()仅在1.7之后的jQuery中可用,之前它是live()。 尝试这个。 http://jsfiddle.net/Upvfx/1/ function showSub(){ alert('wefef'); } $('.common-main-row').live('click', showSub); 编辑: 我在jsfiddle示例中使用了jQuery 1.8.3。 从1.7开始,on()包含在jQuery中。 http://api.jquery.com/o ...