当前位置: 首页 > news >正文

Go 语言规范学习(2)

文章目录

    • Variables
    • Types
      • Boolean types
      • Numeric types
      • String types
      • Array types
      • Slice types
      • Struct types
      • Pointer types
      • Function types
      • Interface types
        • Basic interfaces
        • Embedded interfaces
        • General interfaces【泛型接口】
        • Implementing an interface【实现一个接口】
      • Map types
      • Channel types

Variables

A variable is a storage location for holding a value. The set of permissible values is determined by the variable’s type.

A variable declaration or, for function parameters and results, the signature of a function declaration or function literal reserves storage for a named variable.

Calling the built-in function new or taking the address of a composite literal allocates storage for a variable at run time. Such an anonymous variable is referred to via a (possibly implicit) pointer indirection.

Structured variables of array, slice, and struct types have elements and fields that may be addressed individually. Each such element acts like a variable.

The static type (or just type) 【静态类型或类型】of a variable is the type given in its declaration, the type provided in the new call or composite literal, or the type of an element of a structured variable.

Variables of interface type also have a distinct dynamic type【动态类型】, which is the (non-interface) type of the value assigned to the variable at run time (unless the value is the predeclared identifier nil, which has no type). The dynamic type may vary during execution but values stored in interface variables are always assignable to the static type of the variable.

var x interface{}  // x is nil and has static type interface{}
var v *T           // v has value nil, static type *T
x = 42             // x has value 42 and dynamic type int
x = v              // x has value (*T)(nil) and dynamic type *T

A variable’s value is retrieved by referring to the variable in an expression; it is the most recent value assigned to the variable. If a variable has not yet been assigned a value, its value is the zero value for its type.

Types

A type determines a set of values together with operations and methods specific to those values. A type may be denoted by a type name, if it has one, which must be followed by type arguments if the type is generic. A type may also be specified using a type literal, which composes a type from existing types.

Type     = TypeName [ TypeArgs ] | TypeLit | "(" Type ")" .
TypeName = identifier | QualifiedIdent .
TypeArgs = "[" TypeList [ "," ] "]" .
TypeList = Type { "," Type } .
TypeLit  = ArrayType | StructType | PointerType | FunctionType | InterfaceType |SliceType | MapType | ChannelType .

The language predeclares certain type names. Others are introduced with type declarations or type parameter lists. Composite types—array, struct, pointer, function, interface, slice, map, and channel types—may be constructed using type literals.

Predeclared types, defined types, and type parameters are called named types【命名类型】. An alias denotes a named type if the type given in the alias declaration is a named type.【注意:类型字面值不是命名类型,比如[]int、struct{} 等是未命名类型】

Boolean types

A boolean type represents the set of Boolean truth values denoted by the predeclared constants true and false. The predeclared boolean type is bool; it is a defined type.

Numeric types

An integer, floating-point, or complex type represents the set of integer, floating-point, or complex values, respectively. They are collectively called numeric types. The predeclared architecture-independent numeric types are:

uint8       the set of all unsigned  8-bit integers (0 to 255)
uint16      the set of all unsigned 16-bit integers (0 to 65535)
uint32      the set of all unsigned 32-bit integers (0 to 4294967295)
uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)int8        the set of all signed  8-bit integers (-128 to 127)
int16       the set of all signed 16-bit integers (-32768 to 32767)
int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64       the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)float32     the set of all IEEE 754 32-bit floating-point numbers
float64     the set of all IEEE 754 64-bit floating-point numberscomplex64   the set of all complex numbers with float32 real and imaginary parts
complex128  the set of all complex numbers with float64 real and imaginary partsbyte        alias for uint8
rune        alias for int32

The value of an n-bit integer is n bits wide and represented using two’s complement arithmetic.【二进制补码表示】


  • 现代计算机普遍用 二进制补码 表示有符号整数(如 Go 的 intint32 等),其规则如下:

    • 最高位为符号位0 表示正数,1 表示负数。

    • 正数:直接存储其二进制形式(如 5 的 8 位补码是 00000101)。

    • 负数

      1. 先取绝对值的二进制表示。
      2. 按位取反0110)。
      3. 加 1
      • 例如,-5 的 8 位补码计算:

        5 的二进制 → 00000101
        按位取反   → 11111010
        加 1       → 11111011 (即 -5 的补码)
        

There is also a set of predeclared integer types with implementation-specific sizes:

uint     either 32 or 64 bits
int      same size as uint
uintptr  an unsigned integer large enough to store the uninterpreted bits of a pointer value

To avoid portability issues all numeric types are defined types 【定义的类型是一个新的类型】and thus distinct except byte, which is an alias for uint8, and rune, which is an alias for int32. Explicit conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.

byte类型和uint8类型是相同的类型,rune类型和int32类型是相同的类型,其他的数值类型都不相同,在表达式或赋值中需要显示的转换。

String types

A string type represents the set of string values. A string value is a (possibly empty) sequence of bytes. The number of bytes is called the length of the string and is never negative. Strings are immutable: once created, it is impossible to change the contents of a string【字符串是不可变的】. The predeclared string type is string; it is a defined type.

The length of a string s can be discovered using the built-in function len. The length is a compile-time constant if the string is a constant. A string’s bytes can be accessed by integer indices 0 through len(s)-1. It is illegal to take the address of such an element; if s[i] is the i’th byte of a string, &s[i] is invalid.

Array types

An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length of the array and is never negative.

ArrayType   = "[" ArrayLength "]" ElementType .
ArrayLength = Expression .
ElementType = Type .

The length is part of the array’s type; it must evaluate to a non-negative constant representable by a value of type int. The length of array a can be discovered using the built-in function len. The elements can be addressed by integer indices 0 through len(a)-1. Array types are always one-dimensional but may be composed to form multi-dimensional types.

[32]byte
[2*N] struct { x, y int32 }
[1000]*float64
[3][5]int
[2][2][2]float64  // same as [2]([2]([2]float64))

An array type T may not have an element of type T, or of a type containing T as a component, directly or indirectly, if those containing types are only array or struct types.【注意!】

// invalid array types
type (T1 [10]T1                 // element type of T1 is T1T2 [10]struct{ f T2 }     // T2 contains T2 as component of a structT3 [10]T4                 // T3 contains T3 as component of a struct in T4T4 struct{ f T3 }         // T4 contains T4 as component of array T3 in a struct
)// valid array types
type (T5 [10]*T5                // T5 contains T5 as component of a pointerT6 [10]func() T6          // T6 contains T6 as component of a function typeT7 [10]struct{ f []T7 }   // T7 contains T7 as component of a slice in a struct
)

Slice types

A slice is a descriptor for a contiguous segment of an underlying array and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. The number of elements is called the length of the slice and is never negative. The value of an uninitialized slice is nil.

SliceType = "[" "]" ElementType .

The length of a slice s can be discovered by the built-in function len; unlike with arrays it may change during execution. The elements can be addressed by integer indices 0 through len(s)-1. The slice index of a given element may be less than the index of the same element in the underlying array.

A slice, once initialized, is always associated with an underlying array that holds its elements. A slice therefore shares storage with its array and with other slices of the same array; by contrast, distinct arrays always represent distinct storage.

The array underlying a slice may extend past the end of the slice. The capacity 【容量】is a measure of that extent: it is the sum of the length of the slice and the length of the array beyond the slice; a slice of length up to that capacity can be created by slicing a new one from the original slice. The capacity of a slice a can be discovered using the built-in function cap(a).

A new, initialized slice value for a given element type T may be made using the built-in function make, which takes a slice type and parameters specifying the length and optionally the capacity. A slice created with make always allocates a new, hidden array to which the returned slice value refers. That is, executing

make([]T, length, capacity)

produces the same slice as allocating an array and slicing it, so these two expressions are equivalent:

make([]int, 50, 100)
new([100]int)[0:50]

Like arrays, slices are always one-dimensional but may be composed to construct higher-dimensional objects. With arrays of arrays, the inner arrays are, by construction, always the same length; however with slices of slices (or arrays of slices), the inner lengths may vary dynamically. Moreover, the inner slices must be initialized individually.

Struct types

A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or implicitly (EmbeddedField). Within a struct, non-blank field names must be unique.

StructType    = "struct" "{" { FieldDecl ";" } "}" .
FieldDecl     = (IdentifierList Type | EmbeddedField) [ Tag ] .
EmbeddedField = [ "*" ] TypeName [ TypeArgs ] .
Tag           = string_lit .
// An empty struct.
struct {}// A struct with 6 fields.
struct {x, y intu float32_ float32  // paddingA *[]intF func()
}

A field declared with a type but no explicit field name is called an embedded field【嵌入字段】. An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type or type parameter. The unqualified type name acts as the field name.

// A struct with four embedded fields of types T1, *T2, P.T3 and *P.T4
struct {T1        // field name is T1*T2       // field name is T2P.T3      // field name is T3*P.T4     // field name is T4x, y int  // field names are x and y
}

The following declaration is illegal because field names must be unique in a struct type:

struct {T     // conflicts with embedded field *T and *P.T*T    // conflicts with embedded field T and *P.T*P.T  // conflicts with embedded field T and *T
}

A field or method f of an embedded field in a struct x is called promoted【提升】 if x.f is a legal selector that denotes that field or method f.


For a primary expression x that is not a package name, the selector expression

x.f

denotes the field or method f of the value x (or sometimes *x; see below). The identifier f is called the (field or method) selector【选择器】; it must not be the blank identifier. The type of the selector expression is the type of f. If x is a package name, see the section on qualified identifiers.

A selector f may denote a field or method f of a type T, or it may refer to a field or method f of a nested embedded field of T.

The number of embedded fields traversed to reach f is called its depth in T. The depth of a field or method f declared in T is zero. The depth of a field or method f declared in an embedded field A in T is the depth of f in A plus one.

The following rules apply to selectors:

  1. For a value x of type T or *T where T is not a pointer or interface type, x.f denotes the field or method at the shallowest depth in T where there is such an f. If there is not exactly one f with shallowest depth, the selector expression is illegal.
  2. For a value x of type I where I is an interface type, x.f denotes the actual method with name f of the dynamic value of x. If there is no method with name f in the method set of I, the selector expression is illegal.
  3. As an exception, if the type of x is a defined pointer type and (*x).f is a valid selector expression denoting a field (but not a method), x.f is shorthand for (*x).f.
  4. In all other cases, x.f is illegal.
  5. If x is of pointer type and has the value nil and x.f denotes a struct field, assigning to or evaluating x.f causes a run-time panic.
  6. If x is of interface type and has the value nil, calling or evaluating the method x.f causes a run-time panic.

Promoted fields 【提升的字段】act like ordinary fields of a struct except that they cannot be used as field names in composite literals of the struct.


提升字段(Promoted fields)指通过结构体嵌入(embedded fields)机制,将内部嵌套结构体的字段或方法自动提升到外层结构体的语法特性。其核心规则是:

  1. 类似普通字段
    提升字段在外层结构体中可直接访问,就像属于外层结构体自身定义的字段一样:

    type Address struct { City string }
    type User struct {Name stringAddress // 嵌入字段(Address 的字段会被提升)
    }u := User{}
    u.City = "Beijing" // 直接访问提升字段(等同于 u.Address.City)
    
  2. 复合字面量中的限制
    提升字段不能直接用作复合字面量(struct literal)的字段名,必须通过嵌入类型名显式指定:

    // 错误写法(编译报错)
    u := User{Name: "Alice",City: "Shanghai", // 错误:City 是提升字段,不能直接使用
    }// 正确写法
    u := User{Name: "Alice",Address: Address{City: "Shanghai"}, // 必须通过嵌入类型名初始化
    }
    

结构体类型的方法集

Given a struct type S and a type name T, promoted methods are included in the method set of the struct as follows:

  • ​ If S contains an embedded field T, the method sets【方法集】 of S and *S both include promoted methods with receiver T. The method set of *S also includes promoted methods with receiver *T.
  • ​ If S contains an embedded field *T, the method sets of S and *S both include promoted methods with receiver T or *T.

A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. An empty tag string is equivalent to an absent tag. The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored.

struct {x, y float64 ""  // an empty tag string is like an absent tagname string  "any string is permitted as a tag"_    [4]byte "ceci n'est pas un champ de structure"
}// A struct corresponding to a TimeStamp protocol buffer.
// The tag strings define the protocol buffer field numbers;
// they follow the convention outlined by the reflect package.
struct {microsec  uint64 `protobuf:"1"`serverIP6 uint64 `protobuf:"2"`
}

A struct type T may not contain a field of type T, or of a type containing T as a component, directly or indirectly, if those containing types are only array or struct types.

// invalid struct types
type (T1 struct{ T1 }            // T1 contains a field of T1T2 struct{ f [10]T2 }      // T2 contains T2 as component of an arrayT3 struct{ T4 }            // T3 contains T3 as component of an array in struct T4T4 struct{ f [10]T3 }      // T4 contains T4 as component of struct T3 in an array
)// valid struct types
type (T5 struct{ f *T5 }         // T5 contains T5 as component of a pointerT6 struct{ f func() T6 }   // T6 contains T6 as component of a function typeT7 struct{ f [10][]T7 }    // T7 contains T7 as component of a slice in an array
)

Pointer types

A pointer type denotes the set of all pointers to variables of a given type, called the base type of the pointer. The value of an uninitialized pointer is nil.

PointerType = "*" BaseType .
BaseType    = Type .
*Point
*[4]int

Function types

A function type denotes the set of all functions with the same parameter and result types. The value of an uninitialized variable of function type is nil.

FunctionType  = "func" Signature .
Signature     = Parameters [ Result ] .
Result        = Parameters | Type .
Parameters    = "(" [ ParameterList [ "," ] ] ")" .
ParameterList = ParameterDecl { "," ParameterDecl } .
ParameterDecl = [ IdentifierList ] [ "..." ] Type .

Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent. If present, each name stands for one item (parameter or result) of the specified type and all non-blank names in the signature must be unique. If absent, each type stands for one item of that type. Parameter and result lists are always parenthesized except that if there is exactly one unnamed result it may be written as an unparenthesized type.【如果返回结果只有一个类型,可以省略掉括号】

The final incoming parameter in a function signature may have a type prefixed with .... A function with such a parameter is called variadic【变参函数】 and may be invoked with zero or more arguments for that parameter.

func()
func(x int) int
func(a, _ int, z float32) bool
func(a, b int, z float32) (bool)
func(prefix string, values ...int)
func(a, b int, z float64, opt ...interface{}) (success bool)
func(int, int, float64) (float64, *[]int)
func(n int) func(p *T)

Interface types

An interface type defines a type set. A variable of interface type can store a value of any type that is in the type set of the interface. Such a type is said to implement the interface. The value of an uninitialized variable of interface type is nil.

InterfaceType  = "interface" "{" { InterfaceElem ";" } "}" .
InterfaceElem  = MethodElem | TypeElem .
MethodElem     = MethodName Signature .
MethodName     = identifier .
TypeElem       = TypeTerm { "|" TypeTerm } .
TypeTerm       = Type | UnderlyingType .
UnderlyingType = "~" Type .

An interface type is specified by a list of interface elements. An interface element is either a method or a type element, where a type element is a union of one or more type terms. A type term is either a single type or a single underlying type.

Basic interfaces

In its most basic form an interface specifies a (possibly empty) list of methods. The type set defined by such an interface is the set of types which implement all of those methods, and the corresponding method set consists exactly of the methods specified by the interface. Interfaces whose type sets can be defined entirely by a list of methods are called basic interfaces.

// A simple File interface.
interface {Read([]byte) (int, error)Write([]byte) (int, error)Close() error
}

The name of each explicitly specified method must be unique and not blank.

interface {String() stringString() string  // illegal: String not unique_(x int)         // illegal: method must have non-blank name
}

More than one type may implement an interface. For instance, if two types S1 and S2 have the method set

func (p T) Read(p []byte) (n int, err error)
func (p T) Write(p []byte) (n int, err error)
func (p T) Close() error

(where T stands for either S1 or S2) then the File interface is implemented by both S1 and S2, regardless of what other methods S1 and S2 may have or share.

Every type that is a member of the type set of an interface implements that interface. Any given type may implement several distinct interfaces. For instance, all types implement the empty interface which stands for the set of all (non-interface) types:

interface{}

For convenience, the predeclared type any is an alias for the empty interface. [Go 1.18]

Similarly, consider this interface specification, which appears within a type declaration to define an interface called Locker:

type Locker interface {Lock()Unlock()
}

If S1 and S2 also implement

func (p T) Lock() { … }
func (p T) Unlock() { … }

they implement the Locker interface as well as the File interface.

Embedded interfaces

In a slightly more general form an interface T may use a (possibly qualified) interface type name E as an interface element. This is called embedding interface E in T [Go 1.14]. The type set of T is the intersection【交集】 of the type sets defined by T’s explicitly declared methods and the type sets of T’s embedded interfaces. In other words, the type set of T is the set of all types that implement all the explicitly declared methods of T and also all the methods of E [Go 1.18].

type Reader interface {Read(p []byte) (n int, err error)Close() error
}type Writer interface {Write(p []byte) (n int, err error)Close() error
}// ReadWriter's methods are Read, Write, and Close.
type ReadWriter interface {Reader  // includes methods of Reader in ReadWriter's method setWriter  // includes methods of Writer in ReadWriter's method set
}

When embedding interfaces, methods with the same names must have identical signatures.

type ReadCloser interface {Reader   // includes methods of Reader in ReadCloser's method setClose()  // illegal: signatures of Reader.Close and Close are different
}
General interfaces【泛型接口】

In their most general form, an interface element may also be an arbitrary type term T, or a term of the form ~T specifying the underlying type T, or a union of terms t1|t2|…|tn [Go 1.18]. Together with method specifications, these elements enable the precise definition of an interface’s type set as follows:

  • The type set of the empty interface is the set of all non-interface types.
  • The type set of a non-empty interface is the intersection of the type sets of its interface elements.
  • The type set of a method specification is the set of all non-interface types whose method sets include that method.
  • The type set of a non-interface type term is the set consisting of just that type.
  • The type set of a term of the form ~T is the set of all types whose underlying type is T.
  • The type set of a union of terms t1|t2|…|tn is the union of the type sets of the terms.

The quantification “the set of all non-interface types” refers not just to all (non-interface) types declared in the program at hand, but all possible types in all possible programs, and hence is infinite.

Similarly, given the set of all non-interface types that implement a particular method, the intersection of the method sets of those types will contain exactly that method, even if all types in the program at hand always pair that method with another method.

By construction, an interface’s type set never contains an interface type.

任何接口的类型集合中,永远不会包含其他接口类型(即接口不能直接作为其他接口的实现类型)。

// An interface representing only the type int.
interface {int
}// An interface representing all types with underlying type int.
interface {~int
}// An interface representing all types with underlying type int that implement the String method.
interface {~intString() string
}// An interface representing an empty type set: there is no type that is both an int and a string.
interface {intstring
}

In a term of the form ~T, the underlying type【底层类型】 of T must be itself, and T cannot be an interface.

type MyInt intinterface {~[]byte  // the underlying type of []byte is itself~MyInt   // illegal: the underlying type of MyInt is not MyInt~error   // illegal: error is an interface
}

Union elements denote unions of type sets:

// The Float interface represents all floating-point types
// (including any named types whose underlying types are
// either float32 or float64).
type Float interface {~float32 | ~float64
}

The type T in a term of the form T or ~T cannot be a type parameter, and the type sets of all non-interface terms must be pairwise disjoint (the pairwise intersection of the type sets must be empty). Given a type parameter P:

interface {P                // illegal: P is a type parameter。但是[]P 是合法的!int | ~P         // illegal: P is a type parameter~int | MyInt     // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt)float32 | Float  // overlapping type sets but Float is an interface
}

Implementation restriction: A union (with more than one term) cannot contain the predeclared identifier comparable or interfaces that specify methods, or embed comparable or interfaces that specify methods.

Interfaces that are not basic may only be used as type constraints【类型约束】, or as elements of other interfaces used as constraints. They cannot be the types of values or variables, or components of other, non-interface types.

不是基本接口的接口只能用作类型约束!

var x Float                     // illegal: Float is not a basic interfacevar x interface{} = Float(nil)  // illegaltype Floatish struct {f Float                 // illegal
}

An interface type T may not embed a type element that is, contains, or embeds T, directly or indirectly.

// illegal: Bad may not embed itself
type Bad interface {Bad
}// illegal: Bad1 may not embed itself using Bad2
type Bad1 interface {Bad2
}
type Bad2 interface {Bad1
}// illegal: Bad3 may not embed a union containing Bad3
type Bad3 interface {~int | ~string | Bad3
}// illegal: Bad4 may not embed an array containing Bad4 as element type
type Bad4 interface {[10]Bad4
}
Implementing an interface【实现一个接口】

A type T implements an interface I if

  • T is not an interface and is an element of the type set of I; or
  • T is an interface and the type set of T is a subset of the type set of I.

A value of type T implements an interface if T implements the interface.

Map types

A map is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type. The value of an uninitialized map is nil.

MapType = "map" "[" KeyType "]" ElementType .
KeyType = Type .

The comparison operators == and != must be fully defined for operands of the key type; thus the key type must not be a function, map, or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.

map[string]int
map[*T]struct{ x, y float64 }
map[string]interface{}

The number of map elements is called its length. For a map m, it can be discovered using the built-in function len and may change during execution. Elements may be added during execution using assignments and retrieved with index expressions; they may be removed with the delete and clear built-in function.

A new, empty map value is made using the built-in function make, which takes the map type and an optional capacity hint as arguments:

make(map[string]int)
make(map[string]int, 100)

The initial capacity does not bound its size: maps grow to accommodate the number of items stored in them, with the exception of nil maps. A nil map is equivalent to an empty map except that no elements may be added.

Channel types

A channel provides a mechanism for concurrently executing functions to communicate by sending and receiving values of a specified element type. The value of an uninitialized channel is nil.

ChannelType = ( "chan" | "chan" "<-" | "<-" "chan" ) ElementType .

The optional <- operator specifies the channel direction, send or receive. If a direction is given, the channel is directional, otherwise it is bidirectional.

A channel may be constrained only to send or only to receive by assignment or explicit conversion.

chan T          // can be used to send and receive values of type T
chan<- float64  // can only be used to send float64s
<-chan int      // can only be used to receive ints

The <- operator associates with the leftmost chan possible:

chan<- chan int    // same as chan<- (chan int)
chan<- <-chan int  // same as chan<- (<-chan int)
<-chan <-chan int  // same as <-chan (<-chan int)
chan (<-chan int)

A new, initialized channel value can be made using the built-in function make, which takes the channel type and an optional capacity as arguments:

make(chan int, 100)

The capacity, in number of elements, sets the size of the buffer in the channel. If the capacity is zero or absent, the channel is unbuffered and communication succeeds only when both a sender and receiver are ready. Otherwise, the channel is buffered and communication succeeds without blocking if the buffer is not full (sends) or not empty (receives). A nil channel is never ready for communication.

A channel may be closed with the built-in function close. The multi-valued assignment form of the receive operator reports whether a received value was sent before the channel was closed.

A single channel may be used in send statements, receive operations, and calls to the built-in functions cap and len by any number of goroutines without further synchronization. Channels act as first-in-first-out queues. For example, if one goroutine sends values on a channel and a second goroutine receives them, the values are received in the order sent.

相关文章:

Go 语言规范学习(2)

文章目录 VariablesTypesBoolean typesNumeric typesString typesArray typesSlice typesStruct typesPointer typesFunction typesInterface typesBasic interfacesEmbedded interfacesGeneral interfaces【泛型接口】Implementing an interface【实现一个接口】 Map typesCha…...

XCode中使用MonkeyDev开发iOS版的Comand-line Tool的daemon程序

前提条件&#xff1a;iphone手机越狱ios15&#xff0c;cydia/Sileo中安装好ssh&#xff0c;ldid等相关的常用插件 备注&#xff1a;如何iphone是ios15以下的越狱机&#xff0c;可直接看11步 1. 安装MonkeyDev sudo /bin/sh -c "$(curl -fsSL https://raw.githubusercon…...

Nodejs上传文件的问题

操作系统&#xff1a;window和linux都会遇到 软件环境&#xff1a;v20.10.0的Nodejs 1、前端代码如下&#xff1a; 2、后端Nodejs 2.1、注册接口 2.2、上传接口 其中memoryUpload方法代码如下&#xff1a; 3、用页面上传文件 查看具体报错原因&#xff1a; TypeError: sourc…...

SpringMVC 拦截器详解与实战

在 SpringMVC 框架中&#xff0c;拦截器&#xff08;Interceptor&#xff09;是一种强大的机制&#xff0c;它允许开发者在控制器方法执行前后进行拦截&#xff0c;从而实现诸如用户权限验证、日志记录、性能监控等各种功能。本文将深入探讨 SpringMVC 拦截器的相关知识&#x…...

5.3 MVVM模型

一、MVVM的基本概念 MVVM的基本概念&#xff1a;Model、View、ViewModel 组件职责示例内容Model封装业务数据User类&#xff0c;包含姓名、年龄属性View负责UI呈现XAML界面&#xff0c;包含数据绑定ViewModel连接View和Model&#xff0c;处理视图逻辑MainViewModel包含命令和…...

6、进程理论和简单进程创建

一、了解进程推荐看这个视频&#xff0c;很详细 1、概念 进程(Process)程序的运行过程&#xff0c;是系统进行资源分配和调度的独立单元程序的运行过程&#xff1a;多个不同程序 并发&#xff0c;同一个程序同时执行多个任务。 就需要很多资源来实现这个过程。 每个进程都有一…...

python面试-基础

Python 面试题&#xff1a;解释 filter 函数的工作原理 难度: ⭐⭐ 特点: filter 函数是 Python 内置的高阶函数&#xff0c;用于过滤序列中的元素。这道题考察面试者对函数式编程概念的理解以及对 filter 函数的实际应用能力。和 map 函数类似, Python 3 中的 filter 返回一…...

全分辨率免ROOT懒人精灵-自动化编程思维-设计思路-实战训练

全分辨率免ROOT懒人精灵-自动化编程思维-设计思路-实战训练 1.2025新版懒人精灵-实战红果搜索关键词刷视频&#xff1a;https://www.bilibili.com/video/BV1eK9kY7EWV 2.懒人精灵-全分辨率节点识别&#xff08;红果看广告领金币小实战&#xff09;&#xff1a;https://www.bili…...

前后端常见模型以及相关环境配置介绍

一、前端常见框架 Vue.js 特点&#xff1a;采用数据驱动的响应式编程&#xff0c;组件化的开发模式使得代码结构清晰&#xff0c;易于维护&#xff0c;且学习成本相对较低&#xff0c;适合初学者和快速迭代的项目。应用场景&#xff1a;广泛应用于各类 Web 应用开发&#xff…...

西电考研目前缺额专业,调剂助力上岸!

注意啦&#xff01;准备调剂的兄弟们看过来&#xff1a;今天带大家梳理【西电调剂】的相关内容。助力大家上岸西安电子科技大学研究生 调剂必须在短时间内迅速做出决策&#xff0c;收集信息、筛选院校、准备复试&#xff0c;每一个环节都容不得丝毫懈怠&#xff01;现在除了关注…...

英语四六级听力考试网络广播系统建设方案:助力大学英语四六级听力考试清晰度与可靠性升级

英语四六级听力考试网络广播系统建设方案&#xff1a;助力大学英语四六级听力考试清晰度与可靠性升级 北京海特伟业科技有限公司任洪卓发布于2025年3月26日 一、建设背景&#xff1a;听力考试的重要性与现有系统的痛点 英语四六级考试听力部分作为学生英语听力能力的直接检验…...

性能比拼: Rust vs C++

本内容是对知名性能评测博主 Anton Putra 1个月前 Rust vs C Performance 内容的翻译与整理, 有适当删减, 相关指标和结论以原作为准 介绍 在本视频中&#xff0c;将对比 Rust 和 C。 会使用 Axum 框架的一个稍微改进的版本&#xff0c;该框架基于 Hyper 和 Tokio 运行时&am…...

b站视频提取mp4方案

引言 对于b站视频&#xff0c;有些视频是不能提取字幕的&#xff0c;所以我们想把对应的视频下载下来&#xff0c;然后进行对应的本地处理&#xff0c;获得所需的自由处理&#xff0c;吞食视频。 整体思路 下载b站客户端 ----> 把缓存路径修改------> 下载所需视频---…...

PyQt6实例_批量下载pdf工具_exe使用方法

目录 前置&#xff1a; 工具使用方法&#xff1a; step one 获取工具 step two 安装 step three 使用 step four 卸载 链接 前置&#xff1a; 1 批量下载pdf工具是基于博文 python_巨潮年报pdf下载-CSDN博客 &#xff0c;将这个需求创建成界面应用&#xff0c;达到可…...

【java笔记】泛型、包装类、自动装箱拆箱与缓存机制

一、泛型&#xff1a;类型安全的基石 1. 泛型的本质与原理 Java 泛型&#xff08;Generics&#xff09;是 JDK 5 引入的特性&#xff0c;通过类型参数化实现代码的通用性。泛型类、接口和方法允许在定义时声明类型参数&#xff08;如 T、E、K、V&#xff09;&#xff0c;这些…...

计算机网络——传输层(TCP)

传输层 在计算机网络中&#xff0c;传输层是将数据向上向下传输的一个重要的层面&#xff0c;其中传输层中有两个协议&#xff0c;TCP&#xff0c;UDP 这两个协议。 TCP 话不多说&#xff0c;我们直接来看协议报头。 源/目的端口号&#xff1a;表示数据从哪个进程来&#xff0…...

Go 语言规范学习(1)

文章目录 IntroductionNotation示例&#xff08;Go 语言的 if 语句&#xff09;&#xff1a; Source code representationCharacters例子&#xff1a;变量名可以是中文 Letters and digits Lexical elementsCommentsTokensSemicolons例子&#xff1a;查看程序所有的token Ident…...

深入理解椭圆曲线密码学(ECC)与区块链加密

椭圆曲线密码学&#xff08;ECC&#xff09;在现代加密技术中扮演着至关重要的角色&#xff0c;广泛应用于区块链、数字货币、数字签名等领域。由于其在提供高安全性和高效率上的优势&#xff0c;椭圆曲线密码学成为了数字加密的核心技术之一。本文将详细介绍椭圆曲线的基本原理…...

nginx优化(持续更新!!!)

1.调整文件描述符 # 查看当前系统文件描述符限制 ulimit -n# 永久修改文件描述符限制 # 编辑 /etc/security/limits.conf 文件&#xff0c;添加以下内容 * soft nofile 65535 * hard nofile 65535# 编辑 /etc/sysctl.conf 文件&#xff0c;添加以下内容 fs.file-max 655352.调…...

ARCGIS PRO SDK 创建右键菜单

ArcGIS Pro SDK中的弹出式右键菜单常见的在地图视图、布局视图、文件目录等地方&#xff0c;随便右键点击某个文件、要素、要素类&#xff0c;一般都会弹出一个右键菜单。 操作对象右键菜单 refID要素图层esri_mapping_layerContextMenushp图层esri_mapping_unregisteredLaye…...

编译原理——LR分析

文章目录 LR分析概述一、LR分析概述二、LR(0)分析概述&#xff08;一&#xff09;可归前缀和子前缀&#xff08;二&#xff09;识别活前缀的有限自动机&#xff08;三&#xff09;活前缀及可归前缀的一般计算方法&#xff08;四&#xff09;LR(0)项目集规范族的构造 三、SLR(1)…...

css100个问题

一、基础概念 CSS的全称及作用是什么&#xff1f;行内样式、内部样式表、外部样式表的优先级&#xff1f;解释CSS的层叠性&#xff08;Cascading&#xff09;CSS选择器优先级计算规则伪类与伪元素的区别&#xff1f;举例说明!important的作用及使用注意事项如何继承父元素字体…...

js文字两端对齐

目录 一、问题 二、原因及解决方法 三、总结 一、问题 1.text-align: justify; 不就可以了吗&#xff1f;但是实际测试无效 二、原因及解决方法 1.原因&#xff1a;text-align只对非最后一行文字有效。只有一行文字时&#xff0c;text-align无效&#xff0c;要用text-alig…...

Java-面向对象-多态和抽象类

目录 什么是多态&#xff1f; 多态的优点 多态存在的三个必要条件 虚函数 重写 多态的实现方式 什么是抽象类&#xff1f; 继承抽象类 实现抽象方法 抽象类总结 什么是多态&#xff1f; 多态就是一个行为具有多种不同的表现形式。 举例&#xff1a; 我们按下 F1 键…...

前端性能优化:深入解析哈希算法与TypeScript实践

/ 示例&#xff1a;开放寻址哈希表核心实现 class OpenAddressingHashTable<T> {private size: number;private keys: (string | null)[];private values: (T | null)[];private tombstone Symbol(Deleted);constructor(size: number 53) {this.size size;this.keys …...

车架号查询车牌号接口如何用Java对接

一、什么是车架号查询车牌号接口&#xff1f; 车架号查询车牌号接口&#xff0c;即传入车架号&#xff0c;返回车牌号、车型编码、初次登记日期信息。车架号又称车辆VIN码&#xff0c;车辆识别码。 二、如何用Java对接该接口&#xff1f; 下面我们以阿里云接口为例&#xff0…...

linux input子系统深度剖析

input 就是输入的意思&#xff0c;因此 input 子系统就是管理输入的子系统&#xff0c;和 pinctrl 、 gpio 子系统 一样&#xff0c;都是 Linux 内核针对某一类设备而创建的框架。比如按键输入、键盘、鼠标、触摸屏等 等这些都属于输入设备&#xff0c;不同的输入设备…...

香蕉派 BPI-CM6 工业级核心板采用进迭时空K1 8核 RISC-V 芯片开发

BPI-CM6 产品介绍 香蕉派BPI-CM6是一款工业级RISC-V核心板&#xff0c;它采用SpacemiT K1 8核RISC-V芯片设计&#xff0c;CPU集成2.0 TOPs AI计算能力。8/16G DDR和8/16/32/128G eMMC。设计了板对板连接器&#xff0c;以增强稳定性&#xff0c;与树莓派CM4尺寸相同&#xff0c…...

9.4分漏洞!Next.js Middleware鉴权绕过漏洞安全风险通告

今日&#xff0c;亚信安全CERT监控到安全社区研究人员发布安全通告&#xff0c;Next.js 存在一个授权绕过漏洞&#xff0c;编号为 CVE-2025-29927。攻击者可能通过发送精心构造的 x-middleware-subrequest 请求头绕过中间件安全控制&#xff0c;从而在未授权的情况下访问受保护…...

【Unity3D实现UI轮播效果】

系列文章目录 unity工具 文章目录 系列文章目录👉前言👉一、效果展示👉二、实现步骤👉2-1、搭建UI👉2-2、代码实现👉2-3、代码挂载使用👉三、扩展实现👉壁纸分享👉总结👉前言 功能需求如图所示,点击下一个按钮,所有卡片向右滚动,其中最后一张需要变更…...

谈谈 Webpack 中的 Loader 和 Plugin,它们的区别是什么?

Webpack Loader与Plugin深度解析 作为前端工程化的核心工具&#xff0c;Webpack的Loader和Plugin机制是其强大扩展能力的基石。 理解它们的差异和适用场景&#xff0c;是构建高效打包体系的关键。 我们将从底层原理到实际应用&#xff0c;深入剖析两者的区别。 核心概念对比…...

C#单例模式

单例模式 (Singleton),保证一个类仅有一个实例&#xff0c;并提供一个访问它的全局访问点。通常我们可以让一个全局变量使得一个对象被访问&#xff0c;但它不能防止你实例化对个对象&#xff0c;一个最好的办法就是&#xff0c;让类自身负责保护它的唯一实例。这个类可以保证没…...

Oracle 数据库通过exp/imp工具迁移指定数据表

项目需求&#xff1a;从prod数据库迁移和复制2个表(BANK_STATE&#xff0c;HBS)的数据到uat数据库环境。 数据库版本&#xff1a;Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 迁移工具&#xff1a;客户端exp/imp工具 -- 执行命令 从Prod数据库导出数据exp us…...

MongoDB 与 Elasticsearch 使用场景区别及示例

一、核心定位差异 ‌MongoDB‌ ‌定位‌&#xff1a;通用型文档数据库&#xff0c;侧重数据的存储、事务管理及结构化查询&#xff0c;支持 ACID 事务‌。‌典型场景‌&#xff1a; 动态数据结构存储&#xff08;如用户信息、商品详情&#xff09;‌。需事务支持的场景&#xf…...

PyTorch生成式人工智能实战:从零打造创意引擎

PyTorch生成式人工智能实战&#xff1a;从零打造创意引擎 0. 前言1. 生成式人工智能1.1 生成式人工智能简介1.2 生成式人工智能技术 2. Python 与 PyTorch2.1 Python 编程语言2.2 PyTorch 深度学习库 3. 生成对抗网络3.1 生成对抗网络概述3.2 生成对抗网络应用 4. Transformer4…...

蓝桥杯高频考点——二分(含C++源码)

二分 基本框架整数查找&#xff08;序列二分的模版题 建议先做&#xff09;满分代码及思路solution 子串简写满分代码及思路solution 1&#xff08;暴力 模拟双指针70分&#xff09;solution 2&#xff08;二分 AC&#xff09; 管道满分代码及思路样例解释与思路分析solution 最…...

VUE3项目VITE打包优化

VUE3项目VITE打包优化 代码加密依赖配置效果对比图 自动导入依赖配置 代码压缩依赖配置效果对比图 图片压缩依赖配置效果对比图 字体压缩总结与实践运用效果 代码加密 依赖 npm install -D vite-plugin-bundle-obfuscator配置 import vitePluginBundleObfuscator from "…...

IP 分片重组与 TCP 会话重组

1. IP 分片重组&#xff08;IP Fragmentation & Reassembly&#xff09; &#xff08;1&#xff09;分片原因 当 IP 数据包长度超过 MTU&#xff08;Maximum Transmission Unit&#xff09;&#xff08;如以太网默认 1500 字节&#xff09;时&#xff0c;路由器或发送端会…...

《Python实战进阶》No34:卷积神经网络(CNN)图像分类实战

第34集&#xff1a;卷积神经网络&#xff08;CNN&#xff09;图像分类实战 摘要 卷积神经网络&#xff08;CNN&#xff09;是计算机视觉领域的核心技术&#xff0c;特别擅长处理图像分类任务。本集将深入讲解 CNN 的核心组件&#xff08;卷积层、池化层、全连接层&#xff09;…...

【Django】教程-1-安装+创建项目+目录结构介绍

欢迎关注我&#xff01;后续会更新django教程。一周2-3更&#xff0c;欢迎跟进&#xff0c;本周会更新第一个Demo的单独一个模块的增删改查【Django】教程-4-一个增删改查的Demo【Django】教程-2-前端-目录结构介绍【Django】教程-3-数据库相关介绍 1.项目创建 1.1 安装 Djan…...

力扣DAY29 | 热100 | 删除链表的倒数第N个结点

前言 中等 √ 链表心得&#xff1a;考虑好边界情况。 题目 给你一个链表&#xff0c;删除链表的倒数第 n 个结点&#xff0c;并且返回链表的头结点。 示例 1&#xff1a; 输入&#xff1a;head [1,2,3,4,5], n 2 输出&#xff1a;[1,2,3,5]示例 2&#xff1a; 输入&#…...

渗透测试过-关于学习Token、JWT、Cookie等验证授权方式的总结

关于学习Token、JWT、Cookie等验证授权方式的总结 目录 一、为什么Cookie无法防止CSRF攻击&#xff0c;而Token可以&#xff1f; 二、为什么无论采用Cookie-session的方式&#xff0c;还是Token&#xff08;JWT&#xff09;的方式&#xff0c;在一个浏览器里&#xff0c;同一个…...

C#从入门到精通(3)

目录 第九章 窗体 &#xff08;1&#xff09;From窗体 &#xff08;2&#xff09;MDI窗体 &#xff08;3&#xff09;继承窗体 第十章 控件 &#xff08;1&#xff09;控件常用操作 &#xff08;2&#xff09;Label控件 &#xff08;3&#xff09;Button控件 &…...

greenhill编译出现:3201原因错误

ecom800: 21Mar25 16:26:45.609351: No licenses available for ecom800 Reason: ecom800 (3201): The License Manager cannot be contacted. 解决方式&#xff1a;重新加载lincese驱动。 检查是否安装正确: 检查驱动是否正确识别&#xff1a; 以上检查都正常&#xff0c…...

Docker 快速入门指南

Docker 快速入门指南 1. Docker 常用指令 Docker 是一个轻量级的容器化平台&#xff0c;可以帮助开发者快速构建、测试和部署应用程序。以下是一些常用的 Docker 命令。 1.1 镜像管理 # 搜索镜像 docker search <image_name># 拉取镜像 docker pull <image_name>…...

RISC-V AIA学习2---IMSIC

我在学习文档这章时&#xff0c;对技术术语不太理解&#xff0c;所以用比较恰当的比喻来让自己更好的理解。 比较通俗的理解&#xff1a; 将 RISC-V 系统比作一个工厂&#xff1a; hart → 工厂的一条独立生产线IMSIC → 每条生产线配备的「订单接收员」MSI 中断 → 客户通过…...

C#基础学习(五)函数中的ref和out

1. 引言&#xff1a;为什么需要ref和out&#xff1f; ​问题背景&#xff1a;函数参数默认按值传递&#xff0c;值类型在函数内修改不影响外部变量&#xff1b;引用类型重新赋值时外部对象不变。​核心作用&#xff1a;允许函数内部修改外部变量的值&#xff0c;实现“双向传参…...

【每日算法】Day 9-1:贪心算法精讲——区间调度与最优选择(C++实现)

掌握高效决策的核心思想&#xff01;今日深入解析贪心算法的底层逻辑&#xff0c;聚焦区间调度与最优选择两大高频场景&#xff0c;结合大厂真题与严谨证明&#xff0c;彻底掌握“局部最优即全局最优”的算法哲学。 一、贪心算法核心思想 贪心算法&#xff08;Greedy Algorit…...

Netty源码—8.编解码原理二

大纲 1.读数据入口 2.拆包原理 3.ByteToMessageDecoder解码步骤 4.解码器抽象的解码过程总结 5.Netty里常见的开箱即用的解码器 6.writeAndFlush()方法的大体步骤 7.MessageToByteEncoder的编码步骤 8.unsafe.write()写队列 9.unsafe.flush()刷新写队列 10.如何把对象…...

【踩坑系列】使用httpclient调用第三方接口返回javax.net.ssl.SSLHandshakeException异常

1. 踩坑经历 最近做了个需求&#xff0c;需要调用第三方接口获取数据&#xff0c;在联调时一直失败&#xff0c;代码抛出javax.net.ssl.SSLHandshakeException异常&#xff0c; 具体错误信息如下所示&#xff1a; javax.net.ssl.SSLHandshakeException: sun.security.validat…...