听起来有点奇怪,但是可以final在运行时添加修改器吗?
我有一个标记为的变量public static int/short.在某些时候我想阻止改变它的值,我希望将其可访问性保持为标准静态值(ClassName.field).
public class Main {
private static int a = 0;
public static void addFinalMod(Field f) {
Field modifiersField = null;
try {
modifiersField = Field.class.getDeclaredField("modifiers");
}
catch (NoSuchFieldException e) {
e.printStackTrace();
}
modifiersField.setAccessible(true);
try {
modifiersField.setInt(f, f.getModifiers() & Modifier.FINAL);
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(a);
try {
Field f = Main.class.getDeclaredField("a");
addFinalMod(f);
}
catch (NoSuchFieldException e) {
e.printStackTrace();
}
a = …Run Code Online (Sandbox Code Playgroud) 我有一堆正则表达式,如lower =/[az] /稍后在我的程序中我需要使用它作为/ [az]/g ie.我需要稍后添加'全局'修饰符.那么如何在现有的正则表达式中添加修饰符呢?
我正在使用全局修饰符的基本php示例,它对我不起作用: - |
$a = 1;
$b = 2;
function Sum()
{
global $a, $b;
$b = $a + $b;
}
Sum();
echo "***: ".$b;
Run Code Online (Sandbox Code Playgroud)
这是结果...... $***:2
php.ini上有没有可能影响这个的参数?
只是一个简单的问题。我找不到Swift 修饰符的默认值.padding()。
ModelSelectorItem(variant: variant)
.padding()
Run Code Online (Sandbox Code Playgroud)
我知道我可以省略该值,并且 swift 会自行提供默认值。
.padding()问: SwiftUI 中修饰符的默认值是多少?
我在两个不同的包中有两个类:
package package1;
public class Class1 {
public void tryMePublic() {
}
protected void tryMeProtected() {
}
}
package package2;
import package1.Class1;
public class Class2 extends Class1 {
doNow() {
Class1 c = new Class1();
c.tryMeProtected(); // ERROR: tryMeProtected() has protected access in Class1
tryMeProtected(); // No error
}
}
Run Code Online (Sandbox Code Playgroud)
我可以理解为什么在调用时没有错误,tryMeProtected()因为Class2它继承了这个方法Class1.
但是,为什么是不是有可能的对象Class2访问此方法的对象上Class1使用 c.tryMeProtected(); ?
我一直收到这个错误:
警告:preg_match()[function.preg-match]:第235行的D:\ xampp\htdocs\administrator\components\com_smms\functions\plugin.php中的未知修饰符't'
上:
$PageContent = preg_replace($result->module_pregmatch, '', $PageContent);
Run Code Online (Sandbox Code Playgroud)
我在$ result-> module_pregmatch上做了一个var_dump,得到以下结果:
string '/<title>(.*)</title>/Ui' (length=23)
string '/<meta[^>]*name=["|\']description["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=77)
string '/<meta[^>]*name=["|\']keywords["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=74)
string '/<meta[^>]*name=["|\']author["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=72)
string '/<meta[^>]*name=["|\']copyright["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=75)
string '/<meta[^>]*name=["|\']robots["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=72)
string '/<meta[^>]*http=equiv=["|\']content-language["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=88)
string '/<meta[^>]*http-equiv=["|\']content-type["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=84)
string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']shortcut[^>]*icon["|\'][^>]*type=["|\']image\/x-icon["|\']\s*\/>/Ui' (length=114)
string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']alternate["|\'][^>]*type=["|\']application\/rss\+xml["|\'][^>]*title=["|\'](.*)["|\'][^>]\/>/Ui' (length=142)
string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']alternate["|\'][^>]*type=["|\']application\/atom\+xml["|\'][^>]*title=["|\'](.*)["|\'][^>]\/>/Ui' (length=143)
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我做错了什么吗?我一直坚持这个错误太久了...
我可以private final在Scala中使用修饰符吗?
鉴于以下代码:
1| class A { def callFoo = foo; private final def foo = "bar of A" }
2| class B extends A { private final def foo = "bar of B"}
3| println((new A()).callFoo)
4| println((new B()).callFoo)
Run Code Online (Sandbox Code Playgroud)
3号线和4号线打印:
1| bar of A
2| bar of A
Run Code Online (Sandbox Code Playgroud)
可以理解为什么第2行不打印,bar of B因为实际上有两个foo定义而B中的后者不会覆盖A中的前者.否则Scala将需要override- 而不是final修饰符.
那么Scala为什么不简单地禁止修饰符的组合private final呢?
我想在 Jetpack Compose 中实现MaterialButtonToggleGroup。该组件如下所示(图片取自此处):

到目前为止,我得到了以下结果:

请注意,存在垂直蓝色边框旁边的垂直灰色边框。在原作中,要么同时出现彩色边框,要么同时出现灰色。为了看得更清楚,看一下这张带有超厚边框的图像:

如何实现两个按钮之间不存在垂直边框?我当前的代码如下所示:
val cornerRadius = 8.dp
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Spacer(modifier = Modifier.weight(1f))
items.forEachIndexed { index, item ->
OutlinedButton(
onClick = { indexChanged(index) },
shape = when (index) {
// left outer button
0 -> RoundedCornerShape(topStart = cornerRadius, topEnd = 0.dp, bottomStart = cornerRadius, bottomEnd = 0.dp)
// right outer button
items.size - 1 -> RoundedCornerShape(topStart = 0.dp, topEnd = cornerRadius, bottomStart = 0.dp, bottomEnd = cornerRadius) …Run Code Online (Sandbox Code Playgroud) android modifier android-button kotlin android-jetpack-compose
我有一个与java中修饰符transient之前的关键字使用相关的问题private.
变量声明:
transient private ResourceBundle pageResourceBundle;
Run Code Online (Sandbox Code Playgroud)
我的班级看起来像这样:
public class LoginViewModel extends AbstractViewModel {
transient private ResourceBundle pageResourceBundle;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
initializeLoginValues();
boolean timeout = BooleanUtils.toBoolean(getHttpServletRequest().getParameter("timeout"));
if (timeout) {
Messagebox.show(pageResourceBundle.getText("MSG_SESSION_HAS_EXPIRED_PLEASE_LOGIN"), pageResourceBundle.getText("LABEL_ALERT"),
Messagebox.OK, Messagebox.ERROR);
}
view.getPage().setTitle(CsdcLicence.get().getApplicationName());
}
Run Code Online (Sandbox Code Playgroud)
我有一些问题.
1.为什么transient在私有变量之前使用关键字?
2.使用此关键字的目的是什么?
我有以下可组合项。
@Composable
fun Temp() {
Row(
modifier = Modifier
.background(Color.Red)
.height(IntrinsicSize.Min)
.fillMaxWidth()
) {
Text(text = "Hello", fontSize = 10.sp)
Icon(
imageVector = Icons.Default.Star,
contentDescription = "Star",
modifier = Modifier.fillMaxHeight()
)
}
}
Run Code Online (Sandbox Code Playgroud)
图标的高度从 24.dp 开始并没有减少。有什么办法可以实现这种行为。我希望图标大小只是父行的高度。如果文字很大。图标尺寸增大。我认为图标最小尺寸必须为 24.dp。如何让图标变小?