| |

VerySource

 Forgot password?
 Register
Search
View: 858|Reply: 4

What is type safety

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-14 17:00:01
| Show all posts |Read mode
When I saw generics today, there was such a paragraph:
Type safety. One of the main goals of generics is to improve the type safety of Java programs. Using generics allows the compiler to know the type restrictions of a variable, which in turn can verify type assumptions to a greater degree. If there is no generic type, then the type safety is mainly controlled by the programmer, which is obviously not as safe as a program with a generic type.
I think the type safety is the correct type coercion, so I don't know if it is correct?

2. Another problem is:
The method of thread synchronization can not only let one thread enter this method, does not it seem to be a single thread?
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 22:45:01
| Show all posts
Java generic parameters can only represent classes, not individual objects. Since the actual type of the type parameter of Java generics is eliminated at compile time, it is impossible to know the type of its type parameter at runtime. This will ensure the safety of the program type.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 23:00:01
| Show all posts
Synchronous multithreading (SMT) is a hardware multithreading technology that can execute instructions from multiple threads within a CPU clock cycle. In essence, synchronous multithreading is a method of converting thread-level parallel processing (multiple CPUs) into instruction-level parallel processing (same CPU). Simultaneous multithreading is the ability of a single physical processor to dispatch instructions from multiple hardware thread contexts simultaneously. Synchronous multithreading is used to create performance advantages in commercial environments and for workloads with high cycle/instruction (CPI) counts. The processor adopts a superscalar structure, which is most suitable for reading and running instructions in parallel. Synchronous multithreading allows you to schedule two applications on the same processor at the same time, thereby taking advantage of the superscalar nature of the processor.

So the main benefit of multithreading lies in performance.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 23:15:01
| Show all posts
Generic type safety, to put it bluntly, is to give you RMB in your pocket, and you cannot take out US dollars from your pocket. You can only withdraw RMB.
Without this level of regulation, for example, what you put in is money, but you don’t know what money you withdraw, you have to convert it into the currency used locally (that is, forced conversion). Of course, forced conversion has security problems. I was originally renminbi, and you converted me into a coin! --!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-4 00:30:01
| Show all posts
The synchronization method does make multiple threads become serial
But don’t forget that there is still thread cooperation wait notify
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list