我发现了几个相关(不重复)的问题,但他们并不满足我.
我无法理解使用的位置和原因custom annotations?
我在一本书中读到了一个自定义注释的例子,但没有详细解释.
@interface MyAnno
{
String str();
int val();
}
class MyClass
{
@MyAnno(str = "Annotation example", val = 100)
public static void myMeth()
{
System.out.println("Inside myMeth()");
}
}
class CustomAnno
{
public static void main(String args[])
{
MyClass.myMeth();
}
}
Run Code Online (Sandbox Code Playgroud)
输出符合预期Inside myMeth().
关于这个例子我几乎没有问题.
1 -我如何使用
String str(),并int val()在此计划?要么什么是抽象方法的用途
custom annotation?2-为什么
custom annotations.我的意思是他们对任何代码都有什么影响.3-如何创建一个具有@override效果的注释?(我的意思是任何可以注意到的效果)
如果这个例子对你没用,那么请给我一个合适的小例子,其中使用了a custom annotation.
void demo()
{
printf("demo");
}
int main()
{
printf("%p",(void*)demo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码打印了函数的地址demo.
因此,如果我们可以打印函数的地址,这意味着该函数存在于内存中并占用其中的一些空间.
那么它在内存中占据了多少空间?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
struct emp
{
struct address
{
int a;
};
struct address a1;
};
}
Run Code Online (Sandbox Code Playgroud)
此代码显示警告: -
警告:声明不声明任何内容(默认情况下启用)
以下代码显示无警告的位置
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
struct emp
{
struct address
{
int a;
}a1;
};
}
Run Code Online (Sandbox Code Playgroud)
为什么'警告'仅显示在第一个代码中?
我在"Java - 初学者指南"中阅读了以下代码
interface SomeTest <T>
{
boolean test(T n, T m);
}
class MyClass
{
static <T> boolean myGenMeth(T x, T y)
{
boolean result = false;
// ...
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
以下声明有效
SomeTest <Integer> mRef = MyClass :: <Integer> myGenMeth;
Run Code Online (Sandbox Code Playgroud)
关于上述代码的解释有两点
1 - 当泛型方法被指定为方法引用时,其类型参数
::位于方法名称之前和之后.2 - 如果指定了泛型类,则type参数在类名后面,并在其前面
::.
上面的代码是第一个引用点的示例
有人能为我提供一个实现第二个引用点的代码示例吗?
(基本上我不明白第二个引用点).
struct books
{
char name[100];
float price;
int pages;
};
Run Code Online (Sandbox Code Playgroud)
声明一个结构而不产生object的structure,莫非是结构占用内存空间为它的DATA MEMBERS?
我读的地方,发生违约浮点值一样1.2都double没有float.
那么什么是默认的整数值,比如6,是short , int 还是 long?
我在某处阅读了有关编译器和解释器的以下文档: -
编译器搜索程序的所有错误并列出它们.如果程序没有错误,则将程序代码转换为机器代码,然后程序可以通过单独的命令执行.
解释器按语句检查程序语句的错误.检查一个语句后,它将该语句转换为机器代码,然后执行该语句.该过程一直持续到最后一个程序语句发生.
我怀疑来自以下代码:
int main()
{
printf("hello")
scanf("%d",&j);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用MINGW GCC编译器.当我编译上面的代码后发生以下事情:
首先我得到了错误
error: expected ';' before 'scanf()'
Run Code Online (Sandbox Code Playgroud)
在我纠正上述错误后,我得到第二个错误
error: 'j' undeclared (first use in this function)
Run Code Online (Sandbox Code Playgroud)
所以我想知道为什么两个错误都没有一次列出?
我多次听说过,如果你没有初始化变量,那么garbage value就存储在变量中.
说
int i;
printf("%d",i);
Run Code Online (Sandbox Code Playgroud)
上面的代码打印任何垃圾值,但我想知道如果未初始化,存储垃圾值需要什么?
class Demo
{
public static void main(String args[]) throws java.io.IOException
{
try(FileInputStream fin = new FileInputStream("Demo.txt"))
{
//This block is executed successfully
}
System.out.println("Will it be executed if error occurs in try clause");
}
}
Run Code Online (Sandbox Code Playgroud)
假设代码中的代码try block执行成功,有些代码exception发生try with resource clause,这意味着auto closing文件中发生了异常.
try with resource clause?我想问的是,该异常会被抛到JVM并且会突然终止我的程序并且该println语句不会被执行吗?
我可以捕获该异常,以便还可以执行剩余的程序吗?
c ×7
java ×3
annotations ×1
do-while ×1
function ×1
garbage ×1
generics ×1
int ×1
interpreter ×1
ioexception ×1
long-integer ×1
loops ×1
memory ×1
mingw ×1
object ×1
short ×1
struct ×1
structure ×1
warnings ×1