草庐IT

Final_action

全部标签

java - 没有 happens-before 的安全发布?除了 final 还有什么?

根据JCP(16.2.2.安全发布):Thishappens-beforeguaranteeisactuallyastrongerpromiseofvisibilityandorderingthanmadebysafepublication.WhenXissafelypublishedfromAtoB,thesafepublicationguaranteesvisibilityofthestateofX,butnotofthestateofothervariablesAmayhavetouched.ButifAputtingXonaqueuehappens-beforeBfetches

java - 线程安全但快速访问 "eventually final"变量?

我有一个有点像这样的服务器:classServer{privateWorkingThingworker;publicvoidinit(){runInNewThread({//thiswilltakeaboutaminuteworker=newWorkingThing();});}publicResponsehandleRequest(Requestreq){if(worker==null)thrownewIllegalStateException("Notinitedyet");returnworker.work(req);}}如您所见,有处理请求的线程和初始化服务器的线程。请求可以在

java - 使用 final 字段防止 "this"在构造过程中转义

publicclassApp{privatefinalAa;privatefinalServerserver;publicApp(){a=newA(this);//Bad,thisisescapingbeforeit'sinitialized.}@Subscribe//ThiseventfiressometimeafterAppisfinishedconstructing.publicvoidregisterStuff(RegisterEventevent){server=event.getServer();//Notpossibleduetofinalfieldandthisnotb

java - 为什么将一个final int赋值给一个byte时没有报错

这个问题在这里已经有了答案:WhycannotIaddtwobytesandgetanintandIcanaddtwofinalbytesgetabyte?(3个答案)关闭4年前。为什么会报错inti=123;byteb=i;但在这种情况下不是finalinti=123;byteb=i;

java - 如何使用 final 方法模拟一个类?

假设我有A类classA{finalStringfoo(){//..computingresult,contactingdatabase,whatever..return"somecomputedvalue";}//...andabazillionothermethods,someofthemfinal.}现在我有B类classB{StringmethodIWantToTest(Aa){Stringoutput=a.foo();//...whateverthismethoddoes,e.g.:output+="_suffix";returnoutput;}}我将如何对这个方法进行单元测

java - 重定向到另一个 Action 期间的Struts 2参数编码问题

我尝试重定向到另一个操作并传输一个字符串参数。这没有问题,但如果我使用德语变音符号,我会遇到编码问题。这是我的代码:第一个Action有一个带有getter和setter的字段消息。在操作中我设置了字符串。privateStringmessage;publicStringaction1(){message="ö";returnSUCCESS;}第二个Action也有一个带有getter和setter的字段消息。privateStringmessage;Struts.xml包含两个Action的定义action2${message}/pages/showMessage.jsp如果我不使用

java - 如果一个类被声明为 final 是否有必要将方法声明为 final

我正在阅读一些内容,需要对最终类和方法进行一些说明。我的理解是,将一个类声明为final会阻止该类被扩展。因此,是否有必要将最终类中的方法声明为最终的?在我看来,如果类不能扩展,则没有必要将方法声明为final。 最佳答案 如果类被声明为final,则没有必要将方法声明为final,因为类已经不能被扩展。 关于java-如果一个类被声明为final是否有必要将方法声明为final,我们在StackOverflow上找到一个类似的问题: https://stac

java - JSON Jquery 到 Struts2 Action

我想将我的JSON对象从Javscript发送到Struts2Action。示例JSON对象{"lists":["list1","list2","list3","list4","list5"],"maps":{"key4":"value4","key3":"value3","key5":"value5","key2":"value2","key1":"value1"},"number1":123456789,"numberarray1":[1,2,3,4,5,6,7,8,9],"string1":"A","stringarray1":["A1","B1"]}我的JqueryAjax$.

java - 同步:为什么优先锁定一个private final静态对象而不是类的类对象?

简单问题:为什么这是首选:publicclassFoo{finalprivatestaticObjectfoo=newObject();publicstaticvoiddoSomething(){synchronized(Foo.foo){//code}}}关于这个:publicclassFoo{publicstaticvoiddoSomething(){synchronized(Foo.class){//code}}}或者这个:publicclassFoo{publicsynchronizedstaticvoiddoSomething(){//code}}?对我来说,这些看起来基本相

java - Swing组件的ActionMap中默认 Action 的名称是否标准化?

假设我有一个像JSlider这样的标准Swing组件,但我想稍微调整一下输入映射。默认的inputmaps和actionmap都是lookandfeel安装的,我想复用一些ActionMap中已有的action。为此,我需要将ActionMap条目的键放入InputMap条目的值中。我可以在运行时使用调试器轻松查找ActionMap键(总是一个字符串),并重新使用它。它会工作-保证在我的JDK和L&F版本上。所以问题是,是否在任何地方记录了默认Swing组件操作的键,它们是否会随着时间“合法地”更改(即,从JDK版本到JDK版本或从L&F到L&F)并且您看到这样的更改了吗在实践中?谢谢