在java中,为什么需要将闭包变量声明为final?(in java, why do closured variables need to be declared final?)
final Object o; List l = new ArrayList(){{ // closure over o, in lexical scope this.add(o); }};
为什么必须宣布最终? 为什么其他具有可变变量的JVM语言不具备此要求?
final Object o; List l = new ArrayList(){{ // closure over o, in lexical scope this.add(o); }};
why must
o
be declared final? why don't other JVM languages with mutable vars have this requirement?
原文:https://stackoverflow.com/questions/10626132
更新时间:2021-03-24 06:03
最满意答案
我会认为圆是主要元素,我会使用一个伪元素,我用旋转的SVG背景填充所有这些线。
body { margin::0; overflow:hidden; } .circle { height:100px; width:100px; margin:50px; background:red; border-radius:50%; position:relative; } .circle:before { content:""; position:absolute; top:-5000%; left:-5000%; right:-5000%; bottom:-5000%; background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(20deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(40deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(60deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(80deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(100deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(120deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(140deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(160deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'); background-size:100% 100%; animation:animate 6s infinite linear; } @keyframes animate { from { transform:rotate(0); } to { transform:rotate(360deg); } }
<div class="circle"> </div>
为了使事情变得更容易,您可以依赖JS来生成背景代码:
var all = document.querySelectorAll('.circle'); for (var i = 0; i < all.length; i++) { var c = all[i].getAttribute("data-color"); var s = parseInt(all[i].getAttribute("data-step")); var b = 'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="' + c + '" stroke-width="0.05" /></svg>\')'; var end = 180 / s; for (var j = 1; j < end; j++) { b += ',url(\'data:image/svg+xml,<svg style="transform:rotate(' + s * j + 'deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="' + c + '" stroke-width="0.05" /></svg>\')'; } all[i].style.setProperty("--b", b); all[i].querySelector('span').style.setProperty("background", c); }
body { overflow: hidden; } .circle { height: 100px; width: 100px; position:absolute; } .circle span { position:relative; height:100%; width:100%; display:flex; justify-content:center; align-items:center; z-index:3; border-radius: 50%; color:#fff; } .circle:after { content: ""; z-index: -1; position: absolute; top: -5000%; left: -5000%; right: -5000%; bottom: -5000%; background-image: var(--b); background-size: 100% 100%; animation: animate 10s infinite linear; } @keyframes animate { from { transform: rotate(0); } to { transform: rotate(360deg); } }
<!-- step will define the degree between each line --> <div class="circle" data-color="red" data-step="10"> <span>some text</span> </div> <div class="circle" style="top:150px;left:150px;" data-color="green" data-step="20"> <span>text</span> </div> <div class="circle" style="left:250px;" data-color="orange" data-step="30"> <span>more here</span> </div> <div class="circle" style="right:50px;bottom:50px" data-color="cyan" data-step="10"> <span>more here</span> </div>
I would consider the circle as the main element and I would use a pseudo element that I fill with all these lines using rotated SVG background.
body { margin::0; overflow:hidden; } .circle { height:100px; width:100px; margin:50px; background:red; border-radius:50%; position:relative; } .circle:before { content:""; position:absolute; top:-5000%; left:-5000%; right:-5000%; bottom:-5000%; background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(20deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(40deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(60deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(80deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(100deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(120deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(140deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'), url('data:image/svg+xml,<svg style="transform:rotate(160deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="red" stroke-width="0.05" /></svg>'); background-size:100% 100%; animation:animate 6s infinite linear; } @keyframes animate { from { transform:rotate(0); } to { transform:rotate(360deg); } }
<div class="circle"> </div>
And to make thing easier you may rely on JS to generate the code of the background:
var all = document.querySelectorAll('.circle'); for (var i = 0; i < all.length; i++) { var c = all[i].getAttribute("data-color"); var s = parseInt(all[i].getAttribute("data-step")); var b = 'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="' + c + '" stroke-width="0.05" /></svg>\')'; var end = 180 / s; for (var j = 1; j < end; j++) { b += ',url(\'data:image/svg+xml,<svg style="transform:rotate(' + s * j + 'deg)" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200" height="5000" width="5000"><line x1="100" y1="0" x2="100" y2="200" stroke="' + c + '" stroke-width="0.05" /></svg>\')'; } all[i].style.setProperty("--b", b); all[i].querySelector('span').style.setProperty("background", c); }
body { overflow: hidden; } .circle { height: 100px; width: 100px; position:absolute; } .circle span { position:relative; height:100%; width:100%; display:flex; justify-content:center; align-items:center; z-index:3; border-radius: 50%; color:#fff; } .circle:after { content: ""; z-index: -1; position: absolute; top: -5000%; left: -5000%; right: -5000%; bottom: -5000%; background-image: var(--b); background-size: 100% 100%; animation: animate 10s infinite linear; } @keyframes animate { from { transform: rotate(0); } to { transform: rotate(360deg); } }
<!-- step will define the degree between each line --> <div class="circle" data-color="red" data-step="10"> <span>some text</span> </div> <div class="circle" style="top:150px;left:150px;" data-color="green" data-step="20"> <span>text</span> </div> <div class="circle" style="left:250px;" data-color="orange" data-step="30"> <span>more here</span> </div> <div class="circle" style="right:50px;bottom:50px" data-color="cyan" data-step="10"> <span>more here</span> </div>
相关问答
更多-
理想情况下,人们可以将起点从中心移到左上方,但在这里如何从中心开始。 与您的代码唯一真正的区别仅仅是我要求的开始长度,然后只问问(while循环)是否太长。 忽略我正在使用用于Python 2.x的raw_input ,这同样适用于不带圆括号的打印语句。 import turtle bob = turtle.Turtle() xx,yy= turtle.window_width(), turtle.window_height() print 'window size: ',xx,yy bob.spe ...
-
全屏登录(full screen login)[2022-01-10]
那么,你可以轻松解决这个问题。 你要么做Bastian Rang在他的回答中所说的话,要么你可以继续将这张图片分成两张图片。 所以,登录信息将是一个单独的图像。 通过这种方式,您可以通过css或javascript来调整和调整大小。 并将该登录面板设置为相对位置,您可以轻松地将输入放置在内部并轻松移动。 如有必要,我可以解释更多。 您面临的问题是因为您已将输入区域和背景组合在一起的图像。 将它们分开,它会容易得多。 圣诞快乐,新年快乐! 本着奉献的精神,你去了: [更新] OP的登录设计。 你需要在谷歌浏览 ... -
AVPlayer全屏(AVPlayer Full Screen)[2023-10-23]
你必须提供你自己的按钮。 对于play和pause ,AVPlayer中有直接的API。 对于全屏幕...呃...你知道你在哪里绘制:你只需要将你的UIWindow和相应的UIView&图层设置为全尺寸。 对于搜索,你有像seekToTime:这样的方法seekToTime: You'll have to provide your own buttons. For play and pause there are direct API's in AVPlayer. For full screen… well ... -
将其添加到页面顶部的样式标记中 body, div, svg { margin: 0; border: 0 none; padding: 0; } html, body, div, svg { height: 99%; max-width: 99%; min-height: 90%; } add this in your style tags at the top of the page body, div, svg { margin: 0; b ...
-
我的SVG不会缩放(My SVG won't scale)[2022-08-10]
如果我使用指向SVG的图像标签,并且使用以下CSS,它似乎对我(至少在Firefox中)有效: - #container img { width: 100%; max-height: 100%; } 容器是一个灵活的div,它限制了SVG的大小(这可能是你的表格单元格)。 SVG正在填充容器的宽度,比例保持在pro中,但是如果容器变得太宽,则最大高度会踢入并限制SVG的高度,而不会拉伸。 It seems to work for me (at least in Firefox) if I ... -
动画全屏SVG叠加(Animating full screen SVG Overlay)[2022-07-09]
你必须反转(水平翻转)两个路径定义。 可能不明显的是它们使用小写m ,因此每个坐标对都相对于最后一个坐标对。 例如,原始的起始路径是: m 0,0 1440,0 0,806 0,-806 z 这些点是左上角,右上角,右下角,右上角(按此顺序)。 它动画为: m 0,0 1440,0 0,806 -1440,0 z 或者:左上角,右上角,右下角,左下角。 换句话说,最后一点从右上角移动到左下角。 要改为从左上角到右下角,我们必须颠倒该形状中坐标的顺序。 所以来自: m 1440,0 -1440,0 0,8 ... -
根据Apple的文档,您只需将`MPMoviePlayerController设置为全屏: [moviePlayer setFullscreen:YES animated:YES] 你试过这个吗? As per Apple's documentation, you just have to set the `MPMoviePlayerController to go full screen: [moviePlayer setFullscreen:YES animated:YES] Have you tr ...
-
如何将大小设置为全屏?(How to set size to full screen?)[2023-07-29]
在AndroidManifest.xml中设置主题,让您的应用全屏显示。 您的ImageView将填充父级或匹配父级和根视图以匹配整个屏幕。 希望这有助于并享受您的工作 Set your theme in AndroidManifest.xml for your app to be full screen. Your ImageView to be fill parent or match parent and your root view to match entire screen. Hope this ... -
您应该将.second-content设置为相对的。然后将{position: absolute}添加到其他两个元素。 然后到第一个添加{top: 0}并添加到另一个{bottom: 0} body,html,.second-content {height: 100%; margin: 0} .second-content { background-color: #cccccc; position: relative } .second-content svg:first-child, ...
-
SVG线全屏尺寸(SVG lines full screen size)[2024-03-17]
我会认为圆是主要元素,我会使用一个伪元素,我用旋转的SVG背景填充所有这些线。 body { margin::0; overflow:hidden; } .circle { height:100px; width:100px; margin:50px; background:red; border-radius:50%; position:relative; } .circle:before { content:""; positi ...