我不明白为什么Constructor call must be the first statement in a constructor如果我转移this(1);到构造函数中的最后一行,下面的代码显示错误.
package learn.basic.corejava;
public class A {
int x,y;
A()
{
// this(1);// ->> works fine if written here
System.out.println("1");
this(1); //Error: Constructor call must be the first statement in a constructor
}
A(int a)
{
System.out.println("2");
}
public static void main(String[] args) {
A obj1=new A(2);
}
}
Run Code Online (Sandbox Code Playgroud)
我在StackOverflow上检查了很多关于这个主题的答案,但我仍然无法理解这个原因.请帮我用一些简单的例子和解释来说明这个错误.
我尝试使用<s:url ..标记实现令牌拦截器,但在第一次单击时显示错误.即The form has already been processed or no token was supplied, please try again.
我想实现这个拦截器,因为如果用户已经删除了一行并再次刷新页面,那么同一个动作不应该再次执行.
<s:url id="linkdelete" action="DeleteLatestUpload.action" namespace="/admin/insecure/upload">
<s:param name="latestUploadId" value="latestUploadId"></s:param>
<s:token name="token"></s:token>
</s:url>
<a href='<s:property value="#linkdelete"/>' style="color: white;text-decoration: none;" class="delbuttonlink">Clear current Uploads</a>
Run Code Online (Sandbox Code Playgroud)
和我的struts.xml:
<action name="DeleteLatestUpload" class="v.esoft.actions.UploadExcel" method="deleteUploads">
<interceptor-ref name="token"></interceptor-ref>
<interceptor-ref name="basicStack"></interceptor-ref>
<result name="success" type="tiles"> uploadforward</result>
<result name="invalid.token" type="tiles">uploadforward </result>
</action>
Run Code Online (Sandbox Code Playgroud) 假设我有一个当前的网址显示 http://localhost.com/welcome/blah_blah,从这个网址我希望只能http://localhost.com/ 进入一个页面.
这该怎么做??
我知道echo current_url();给出了完整的网址.但我只想要http://localhost.com排除controller_name,clasname等.
预期产出
如果我的base_url = http://www.exaple.com/folder¤t_url = http://exaple.com/folder/class/method/blah_blah,那么我想要的域名exaple.com不是www.exaple.com !
我正面临一个问题.
正如我所知,构造函数,Instance Initialization块不会继承到子类,但是下面的代码继承了超类构造函数,它为什么要调用?
预期的产出是:来自缺点2
但它的显示输出如下:--IIB--来自cons 2来自cons 2
WHY? this output , *As i know "sub class should not inherit Constructor & IIB block"*
Run Code Online (Sandbox Code Playgroud)
请帮我弄清楚这个概念.
public class X
{
{
System.out.println("--IIB--");
}
X()
{
System.out.println("from cons 1");
}
}
class Y extends X
{
Y()
{
System.out.print("from cons 2");
}
}
class Z
{
public static void main(String args[])
{
Y ob=new Y();
}
}
Run Code Online (Sandbox Code Playgroud)