我有以下代码:
#include <stdio.h>
int main() {
unsigned int a = -1;
int b = -1;
printf("%x\n", a);
printf("%x\n", b);
printf("%d\n", a);
printf("%d\n", b);
printf("%u\n", a);
printf("%u\n", b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
ffffffff
ffffffff
-1
-1
4294967295
4294967295
Run Code Online (Sandbox Code Playgroud)
我可以看到根据传递给printf
函数的值将值解释为有符号或无符号.在这两种情况下,字节都是相同的(ffffffff
).那么,这个unsigned
词是什么意思?
interface Base<T extends Base> {
T method();
}
Run Code Online (Sandbox Code Playgroud)
反对这种模式设计
interface Base {
Base method();
}
Run Code Online (Sandbox Code Playgroud)
唯一的,我想,用method()
在Base
我能得到的具体类型.有更多的好处吗?
1)为什么不允许以下任务:
byte b = 0b11111111; // 8 bits or 1 byte
Run Code Online (Sandbox Code Playgroud)
但是这个任务是允许的:
int i = 0b11111111111111111111111111111111; //32 bits or 4 bytes
Run Code Online (Sandbox Code Playgroud)
两种类型都是签名的,我希望b
并且i
是-1.
2)为什么整数MIN_VALUE没有符号?
public static final int MIN_VALUE = 0x80000000;
Run Code Online (Sandbox Code Playgroud)
但字节MIN_VALUE确实有一个标志?
public static final byte MIN_VALUE = -128;
Run Code Online (Sandbox Code Playgroud) 类型擦除是删除通用信息以便在编译类上向后兼容的过程.然后,我不知道泛型类中的对象是什么类型的类,但是在继承的类中,例如:
package generics.testing;
class Box<T> {
private T value;
public Box() {
System.out.println("GenericSuperClass: " + getClass().getGenericSuperclass());
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
class IntegerBox extends Box<Integer> {}
public class GenericsTesting {
public static void main(String[] args) {
Box<String> box = new Box<>();
IntegerBox ibox = new IntegerBox();
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
GenericSuperClass: class java.lang.Object
GenericSuperClass: generics.testing.Box<java.lang.Integer>
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么generics.testing.Box<java.lang.Integer>
保留这些信息以及存储在哪里?
在我贡献的两个项目中,我遇到了这个错误:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: java.util.Objects
Run Code Online (Sandbox Code Playgroud)
那是因为我已经实现hashCode
和equals
使用方法Objects
的类.
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.image);
hash = 97 * hash + Objects.hashCode(this.car);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final SummaryContent other = (SummaryContent) obj;
if (!Objects.equals(this.image, other.image)) {
return false;
}
return Objects.equals(this.car, other.car);
}
Run Code Online (Sandbox Code Playgroud)
当我编译时,我不会收到错误或警告.为什么会发生这种情况?
如果我有一个像 HelloWorld 这样的 C++ 编写的简单程序,然后我在 32 位和 64 位机器上编译它,我会得到两个不同的二进制文件,但它们是不同的机器代码,只有 32 位二进制文件能够在 32 位或 64 位机器上运行。
在这两种情况下,我都没有任何好处,因为源代码是相同的,而且它们的作用相同。这让我觉得某些为 32 位编写的 Linux 发行版的所有软件包都可以移植到 64 位机器上,而无需做任何更改。那么,我能得到什么?有什么好处吗?
是否有任何 C/C++ 代码示例可以在 64 位中执行而在 32 位中无法执行?
例如,目前 32 位不支持 Google Chrome,但 64 位不支持。这可能是什么原因?
使用Python我可以做下一个:
equals = filecmp.cmp(file_old, file_new)
Run Code Online (Sandbox Code Playgroud)
在go语言中是否有任何内置函数可以做到这一点?我用Google搜索但没有成功.
我可以在hash/crc32
包中使用一些哈希函数,但这比上面的Python代码更有用.
我在JPA 2.1
使用spring-data-jpa
.
根据文档:
5.3.8. 修改查询 以上所有部分都描述了如何声明查询以访问给定的实体或实体集合。当然,您可以使用 Spring Data 存储库的自定义实现中描述的工具添加自定义修改行为。由于这种方式对于全面的自定义功能是可行的,您可以通过使用@Modifying注解查询方法来实现修改实际上只需要参数绑定的查询的执行:
@Modifying
@Query("update User u set u.firstname = ?1 where u.lastname = ?2")
int setFixedFirstnameFor(String firstname, String lastname);
Run Code Online (Sandbox Code Playgroud)
但是我需要更新的实体@ManyToOne
与另一个实体有关系。
@Entity
@Table(name = "usuarios", indexes = {
@Index(name = "idx_usuarios_rut", columnList = "rut")
,@Index(name = "idx_usuarios_email", columnList = "email")})
public class User extends BaseEntity implements UserDetails {
...
@NotNull(message = "Debe seleccionar un nivel")
@ManyToOne(fetch = FetchType.LAZY)
public Role getRole() {
return role;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的UPDATE …
根据对这个问题的回应
有关接收器的指针与值的规则是可以在指针和值上调用值方法,但只能在指针上调用指针方法
但实际上我可以对非指针值执行指针方法:
package main
import "fmt"
type car struct {
wheels int
}
func (c *car) fourWheels() {
c.wheels = 4
}
func main() {
var c = car{}
fmt.Println("Wheels:", c.wheels)
c.fourWheels()
// Here i can execute pointer method on non pointer value
fmt.Println("Wheels:", c.wheels)
}
Run Code Online (Sandbox Code Playgroud)
那么,这里有什么问题?这是一个新功能吗?或者对问题的回答是错误的?
我正在尝试使用方法参数上的 @ModelAttribute 注释注入模型属性。
@RequestMapping({"/", "/index"})
public String home(Principal principal, Model model, @ModelAttribute("commerceId") Long commerceId) {
if (commerceId == null) {
LOGGER.info("Initializing commerce code...");
String name = principal.getName();
commerceId = Long.parseLong(name);
model.addAttribute("commerceId", commerceId);
}
return "index";
}
Run Code Online (Sandbox Code Playgroud)
但我总是得到下一个例外:
java.lang.NoSuchMethodException: java.lang.Long.<init>()
Run Code Online (Sandbox Code Playgroud)
我可以看到 spring 正在尝试使用无参数构造函数创建 Long 值,但显然它会失败,因为 Long 类型没有无参数构造函数。
为什么 Spring 无法使用 @ModelAttribute 正确创建 Long 类型?任何 Wrapper 类型(Integer、Long 等)都可以注入 @ModelAttribute 吗?
我正在使用 Spring 3.1.1
char[] = char *p
char[][] = char **p
Run Code Online (Sandbox Code Playgroud)
但是,当我使用接下来的两个表单初始化一个字符串数组时
char **p = {"Hello", "World"};
char p[][] = {"Hello", "World"};
Run Code Online (Sandbox Code Playgroud)
编译器向我显示了一些错误.
[错误]数组类型具有不完整的元素类型
但随着
char *matriz[] = {"Hello", "World"};
Run Code Online (Sandbox Code Playgroud)
没有警告.我是C语言的新手,我很困惑.
java ×4
c ×3
go ×2
pointers ×2
32bit-64bit ×1
android ×1
arrays ×1
byte ×1
c++ ×1
filecompare ×1
generics ×1
jakarta-ee ×1
jpa ×1
methods ×1
native ×1
oop ×1
primitive ×1
printf ×1
spring ×1
spring-boot ×1
spring-mvc ×1
types ×1
unsigned ×1