将 Boot 与嵌入式服务器一起使用而不是传统地将 war 部署到 Web 服务器有什么优点/缺点?
我意识到它非常适合开发,并且似乎也融入了围绕微服务的大多数讨论中。此模型是否打算部署到生产中?似乎调整嵌入式服务器可能会有问题,更不用说堆要求了。
当我尝试覆盖 的onCreateDialog
方法时androidx.fragment.app.DialogFragment
,出现以下错误:“onCreateDialog 不覆盖任何内容”。
根据developer.android.com,我应该能够覆盖它,因为它被定义为开放。
我正在使用以下代码
import android.app.AlertDialog
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.fragment.app.DialogFragment
class MyDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle): Dialog {
return activity?.let {
val builder = AlertDialog.Builder(it)
builder.setMessage("Yes or no?")
.setPositiveButton("yes",
DialogInterface.OnClickListener { dialog, id ->
// yes
})
.setNegativeButton("no",
DialogInterface.OnClickListener { dialog, id ->
// no
})
builder.create()
} ?: throw IllegalStateException("Activity cannot be null")
}
}
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
我只是在测试代码时注意到一些有趣的事情,我想要更多的解释。为什么函数在同一作用域内的优先级高于 lambda?
例如 :
fun sum(x: Int, y:Int) = x + y
val sum = { x: Int, y: Int -> x + y }
// here, the compiler use the fonction (first line) and not the lambda
println(sum(1, 2))
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我使用invoke()
lambda 而不是函数。
我的理解方式是,“变量”一词指的是重新分配引用的能力。“常量”意味着不能重新分配引用。Java中final和not的本质区别。
var something = new obj() -> reference can be re-assigned
val something = new obj() -> cannot be re-assigned
Run Code Online (Sandbox Code Playgroud)
对我来说,“可变性”意味着修改 REFERAND/OBJECT 本身的能力,而不是修改它的引用。IE被引用的对象。但 Kotlin 并不能阻止这种情况。
你可以有
val something = new obj()
Run Code Online (Sandbox Code Playgroud)
但仍然能够“改变” obj() 而无需重新分配给新的标识符。
我是否误解了什么,或者这是用词不当?
Java新手在这里。
我创建了一个函数来简单地返回用户通过 Scanner 给出的 int 。目标是避免用户未键入整数时出现错误,通知他们并让他们重试。
如果第一次尝试时该值是整数,则它工作正常,但如果我键入一个字符(出现错误,函数“重新启动”),则该函数将返回“默认”零。尝试了不同的事情,但我绝对不明白这里的逻辑。
这是代码:
//Initialize the Scanner earlier
public static Scanner keyBoardRead = new Scanner(System.in);
public static int intEntry()
{
int entry;
keyBoardRead = new Scanner(System.in);
if (keyBoardRead.hasNextInt() == true)
{
entry = keyBoardRead.nextInt();
System.out.println("entry variable = "+entry);
// Here the correct entry prints but doesn't seem to return
return entry;
}
else
{
System.out.println("Invalid entry.\n");
intEntry();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
示例输出:
z
Invalid entry.
2
entry variable = 2
// Function exits and output = …
Run Code Online (Sandbox Code Playgroud) 从我的理解当我们使用像这样的指针创建数组
int **ptr = new int*[2];
for(int i=0;i<2;i++)
{
ptr[i] = new int[3];
}
Run Code Online (Sandbox Code Playgroud)
但是当我们创建这样的静态数组时
int arr[2][3]={1,2,3,4,5,6);
Run Code Online (Sandbox Code Playgroud)
现在如果我们运行以下代码
cout<<"Address of arr = "<<&arr;
cout<<"arr is pointing to = "<<*arr;
Run Code Online (Sandbox Code Playgroud)
它显示了相同的地址,这意味着arr是指向自身的指针,这看起来很混乱,因为如果数组是双指针,那么它如何指向自身.
很明显,编译器正在做一些奇怪的事情.你能解释一下这是如何工作的吗?
如何禁用 Material Design 底部导航菜单项?我可以设置,.isClickable = false
但这不会将菜单项显示为禁用,类似于按钮。我做不到.isEnabled
,API 不允许。
底部导航视图 XML
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/menu_item_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@color/colorDark"
app:menu="@menu/bottom_navigation_menu">
Run Code Online (Sandbox Code Playgroud)
菜单 XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_home"
android:title="Home"
android:icon="@drawable/home_button"
app:showAsAction="ifRoom" />
Run Code Online (Sandbox Code Playgroud)
活动
class Something : AppCompatActivity() {
private lateinit var mHomeBtn: BottomNavigationItemView
override fun onCreate(...) {
mHomeBtn = this.findViewById(R.id.action_home)
mHomeBtn.isClickable = false // <--- will make it unable to click but won't show disabled
mHomeBtn.isEnabled = false // <--- will throw an error
mHomeBtn.setOnClickListener(this)
}
...
Run Code Online (Sandbox Code Playgroud) foo(char *s)
foo(char *s[ ])
foo(char s[ ])
所有这些有什么区别?
有什么方法可以修改作为参数传递的数组的元素,就像我们传递int
或float
使用&
实际参数的值被修改一样?
我是C的新手并且坚持"如何将多维数组传递给函数".我知道你必须传递列大小,这样如果你想要去它a[0][0]
,a[1][0]
它可以计算一维数组的大小,并可以跳过它.
我写了一个小程序:
#include<stdio.h>
void foo(char[][2]);
int main()
{
char arr[2][2] = {'a','b','c','d'};
foo(arr);
return 0;
}
void foo(char temp[][2])
{
temp++;
printf("%c",*temp);
}
Run Code Online (Sandbox Code Playgroud)
我期望这段代码会打印这个字母c
,因为temp
最初指向'a'
并且一旦我们递增它,它将跳过第一个1-d数组并转到第二个1-d数组的第一个元素'c'
.但是我认为这种方式不起作用.
请解释编译器如何计算这些地址.
我已经搜索了这个问题,并且对于同样的问题存在一些问题,但这些问题的答案似乎都没有解决我的问题.
我已经查看了规范,并设法找到以下几点:
第一个表达式到三元必须是boolean类型
第二个和第三个表达式无法调用void方法.
如果我写下面的代码,请给出上述信息
String res;
System.out.println(res="walter");
Run Code Online (Sandbox Code Playgroud)
它将walter打印到控制台,这意味着表达式返回了一些东西,因此它不是空的.但现在如果试着写这个
String stuff = "TV";
String res=null;
stuff.equals ("TV") ? res= "Walter" : res = "White" ;
Run Code Online (Sandbox Code Playgroud)
此代码无法编译 .赋值的左侧必须是变量
即使满足上述两个条件(据我所知).代码为什么不编译以及为什么它需要左边的变量?
而且如果我这样做的话
res = stuff.equals("TV")?res="WALTER":res="WHITE";
Run Code Online (Sandbox Code Playgroud)
代码无法编译
对于参数类型java.lang.String,java.lang.String,运算符<=未定义
但是以下编译好了
res = stuff.equals("TV")?res="WALTER":"WHITE";
Run Code Online (Sandbox Code Playgroud)
PS